Questions tagged [cin]

std::cin is the global stream object provided by the C++ standard library for reading from the standard input stream.

For more general questions about std::istream use the or tags.

1859 questions
0
votes
2 answers

cin.getline() without using string size

Is it possible to use cin.getline() without denoting an array size? That is, with the following pseudo-code: char array[15]; cin.getline(array,'.'); // '.' Is the delimiter. Will this work?
Harjyot Singh
  • 19
  • 1
  • 3
0
votes
2 answers

Problems with cin

I'm using cin in 2 different ways: one way I'm just using cin (overloaded)>> variable, and the other way I'm using a function called read, which takes in an istream. The code I have for it is: cin >> string6; cout << string6; string7.read(cin);…
Jonathan Chiou
  • 349
  • 6
  • 15
0
votes
2 answers

cin.getline() function not working properly after cin?

I am trying the following code: int main() { char str1[20]; int a; cout << "Enter Integer:" cin >> a; cout << "Integer:"<
Altaf Shaikh
  • 729
  • 8
  • 19
0
votes
1 answer

program skip over getline

I am suppose to create a program such that when 'y' is entered it will execute the code in the first do-while loop. however, when 'y' is entered it just skips over the chunk of codes! Enter a phone symbols: a 2 Continue (Y/y): y Enter a phone…
Isabella Chan
  • 41
  • 1
  • 10
0
votes
2 answers

cin error in C++

I am writing a program that will calculate password strength according to two formulas. It requires the user to enter 2 passwords, one being eight characters or less and the other being 20 characters or more. The first parts executes with out…
user3064203
  • 103
  • 1
  • 2
  • 7
0
votes
1 answer

Reading in both doubles and words and performing actions based on what is read

I'm writing a program that takes in input and formats it into a score as "Name Score". Here is what needs to be done "Here's Moonglow's format. The text file is composed of words. If a word is a number, then that is a student's score on a question,…
0
votes
1 answer

using two getline(cin,s) in c++

There's something wrong with my code. I typed something and pressed enter after seeing "the first string"on the screen but I saw a empty new line instead of "the second string". Then I typed something again and pressed enter again. Then I had no…
Kevin
  • 27
  • 5
0
votes
2 answers

Why are there different values for input?

why does when enter 'q' ( or any char) double x; x = cin.get(); cout << x << endl; return the char value for the character entered, but double x; cin >> x; cout << x << endl; returns a random value for 'q'
Bbvarghe
  • 267
  • 2
  • 5
  • 18
0
votes
1 answer

cin into an array structure seems to input nothing

Trying to add a new record into my array of structure members. I have the array populated initially through a file I/O, but trying to add in a new record (before saving to a file) leaves my fields blank. //CONSTANTS const int MAX_GAMEDATA =…
Cam Cole
  • 3
  • 2
0
votes
1 answer

Reading a Text file with Mixed Input using cin and/or strings

I have just begun to tackle a coding problem I must solve, and am unsure how to get started and accomplish the task. There are multiple text files composed of words. If a word is a number, then that is a student's score on a question, so you add it…
jaredthecoder
  • 315
  • 2
  • 3
  • 8
0
votes
3 answers

Why doesn't cin re-prompt if input value exceeds target type size?

I noticed while I was implementing a simple linked-list stack that cin doesn't re-prompt if I enter a value larger than the max. size of an integer. For example: int input; do { cin >> input; if (input == -1) break; else if…
Albert Xing
  • 5,620
  • 3
  • 21
  • 40
0
votes
2 answers

c++ compile time error

I'm learning c++ and trying some things out... The following code is giving me a compile time error, can anyone explain to me why, I'm a little confused... I'm assuming it's the cin >> playagain statement. Thank you for the help. (also if I'm making…
Abdul Ahmad
  • 9,673
  • 16
  • 64
  • 127
0
votes
2 answers

cin.get() getting too much

I want a user to enter a char. I want to filter what they enter and take only the first char they type. int main(){ while (true){ char n = readOption(); cout << n << std::endl; } return 0; } char readOption() { char…
Chronicle
  • 1,565
  • 3
  • 22
  • 28
0
votes
1 answer

std::cin error state and variable changing

I thought that, if cin enters an error state, the variable it is streaming into remains unchanged. However, the following seems to be a counterexample: #include using namespace std; int main() { cout << "Enter int: "; int i = 5; …
bcf
  • 2,104
  • 1
  • 24
  • 43
0
votes
1 answer

C++ Console application cycle

I have console application and I first generate 10 students and then I add them to the Evidence (own double linked list). Then I'm removing student from Evidence, but after second (or highter) removal of student I have infinite cycle, because cin >>…
Pivoman
  • 4,435
  • 5
  • 18
  • 30