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
1 answer

Input with spaces inputs all loops

I have my programs asking for 3 inputs in 3 seperate while loops. How come if i enter 4 2 5 with spaces it fills in all the inputs input1,input2,input3? Is there a way to make it give an error if this happens? int input1 = 0 while (!(cin >>…
tyrone 251
  • 355
  • 1
  • 4
  • 14
0
votes
3 answers

cin throwing error message

I was having issues with another program. It was something like this: if(n < 15000) { printf("I am < 15000"); return 0; } else if(n > 19000) { printf("I am > 19000"); return 0; } else if(n > 51000) { printf("I am > 51000"); …
s4w3d0ff
  • 1,091
  • 10
  • 24
0
votes
1 answer

cin.getline() waiting for input

I'm a beginner making a program in Eclipse IDE (C++) and I've got a problem with a small piece of my code. The problem is shown below: char dataArray[100]; cout<<"Please enter a data set string:…
0
votes
2 answers

Redundant input in cin

What happens with the redundant input we give to a program? Suppose you want to read an integer in variable a from the standard input, but you enter five space separated integers. The terminal gives the first line of input to the program. a is…
LearningMath
  • 851
  • 4
  • 15
  • 38
0
votes
3 answers

Vector size affected by std::cin?

I came across a very strange error where the size of std::vector changes after receiving std::cin input. I've isolated the problem, but I don't understand why this happens: int main() { std::vector asdf; asdf.push_back(1); …
Couchy
  • 753
  • 1
  • 5
  • 25
0
votes
1 answer

Combining Keys with ENTER key

Usually after getting the input using cin we need to press the Enter key for the value to be stored in the variable. Is there a way to combine both of them? (i.e as soon as I press the ESC it should execute the previous screen operation in the below…
Kaushik
  • 1,271
  • 2
  • 18
  • 35
0
votes
3 answers

C++ Only first vector completes, push_back, cin, for loop

I am sure that I am making some obvious mistake. I googled my question but I could not find a similar question; apologies if it is there somewhere. Basically, I just want to complete entries for a series of vectors. The programme compiles, and I can…
0
votes
2 answers

Robust numerical user input function but zero not seen as a number

I have made a function for controlling user input so that the user can input anything and including a long string of letters and the function gives out "Incorrect input" and repeats until a number is input. (These are then used for a switch…
user3343772
  • 5
  • 1
  • 4
0
votes
2 answers

How to make a robust user input for a switch case?

I am trying to make a completely error-proof input for switch cases. It needs to not fail if the user puts in the wrong number, a letter, or a long string of numbers or letters (This is where I have had errors before). To prevent an error if the…
user3343772
  • 5
  • 1
  • 4
0
votes
4 answers

Cin requires 2 inputs

I am trying to make a function that will make sure a number is greater than zero, but whenever the user does not enter a number greater than zero they must enter a value twice before the code will continue. Please help! int userInput() { …
0
votes
2 answers

Differences between using cin.clear();

while(cin.fail()){ cout<<"Error: Your line is too long.\nPlease enter a shorter line: "; cin.clear(cin.good()); cin.ignore(std::numeric_limits::max(),'\n'); cin.getline(name, maxCh); } I'm using…
user3328660
0
votes
1 answer

How to ignore some input when I don't need it for the computation in C++?

The code below just needs to output the sum = unit1 * price1 + unit2 * price2 ; I don't need the code1,code2 of goods. I don't know how to skip them in my program? I did not know - so i had to read them and store them in code1, code2.How to ignore…
ERJAN
  • 23,696
  • 23
  • 72
  • 146
0
votes
1 answer

cin to linked list core dumped

I'm having a problem with cin in c++. I'm trying to cin a text file to the program, and then put all the words etc. in a linked list, but I'm having a problem with the temp->next part, the core gets dumped. string x = ""; //ordet blir lagret…
0
votes
4 answers

cin a fraction of unknown size?

How would one go about overloading the cin >> operator in c++ to input a fraction of unknown size/chars? Specifically, the person can enter 1/2 or 12/4 or 1/100 and it has to be able to accept any of them and input them into a numerator and…
Neko
  • 51
  • 1
  • 1
  • 9
0
votes
1 answer

Tic Tac Toe cin input issue

question on tic tac toe. I'm trying to allow the user to input "0,0"(row/column) format exactly, and would be invalid otherwise. Error is that if I input any of the correct grid numbers, it would give an invalid error regardless. "i.e - '1,2'…
Christian
  • 35
  • 7