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

messy reading from input file into array

I've been workingo n this for a long time so I figured it's time to ask a question as I have no idea what's going on. For whatever reason in this loop, it only works proper through the first time, then it goes back to the beginning of the file and…
lloyd
  • 1,089
  • 1
  • 17
  • 39
0
votes
3 answers

c++ string validation for user input

All I want to do, is prompt a user for a yes or no answer, and validate this to ensure they haven't typed something stupid. I thought this would be a relatively straight forward task, however after many failed attempts at it myself, and looking…
user3001499
  • 811
  • 4
  • 16
  • 32
0
votes
1 answer

Why does cin.ignore() request input?

I discovered some very peculiar behaviour. I'm new to C++ so I found this odd and was unable to explain it after reading the docs on cin.ignore. #include using namespace std; int main() { cout << "Hello world!" << endl; …
user2316667
  • 5,444
  • 13
  • 49
  • 71
0
votes
1 answer

Cin>> multiple times on the same line

I want to use cin>> in c++ to write the values into a bi-dimensional array on the same line..I don't know English very well but I'll show you an example: So I have an array and I want to write in it 24 numbers(4 rows, 6 colons) and I want to input…
Daniel Bejan
  • 1,468
  • 1
  • 15
  • 39
0
votes
1 answer

Converting a prompt-string into an integer

I am trying to issue a prompt to the terminal, which reads an integer, and returns that integer. int prompt(string promptString) { int input = 0; cin >> promptString; input = promptString; return input; } Thank you!
Ganondalf
  • 73
  • 1
  • 5
0
votes
1 answer

Read float values until ENTER

I have to multiply two polynomials. Input: 2 lines of text each containing 1 to 1000 coefficients (floats) separated by spaces. Output: Result of multiplication. I already found the function that will multiply them, but I have no idea how to read…
user2225809
  • 101
  • 1
  • 2
  • 7
0
votes
2 answers

Algo: find max Xor in array for various interval limis, given N inputs, and p,q where 0<=p<=i<=q<=N

the problem statement is the following: Xorq has invented an encryption algorithm which uses bitwise XOR operations extensively. This encryption algorithm uses a sequence of non-negative integers x1, x2, … xn as key. To implement this algorithm…
Pandrei
  • 4,843
  • 3
  • 27
  • 44
0
votes
1 answer

How can I get a cin loop to stop upon the user hitting enter?

Here's my C++ code right now: // Prompt user loop char preInput; do { // Fill the vector with inputs vector userInputs; cout << "Input a set of digits: " << endl; while(cin>>preInput){ if(preInput == 'Q' || preInput ==…
Riptyde4
  • 5,134
  • 8
  • 30
  • 57
0
votes
2 answers

cin function doesn't show local echo

I have a program that scans on user input with i=getchar(); and it works. To prevent that the user has to press Enter every time i used that: tcgetattr(STDIN_FILENO,&old_tio); new_tio=old_tio; new_tio.c_lflag &=(~ICANON & ~ECHO); …
Leonard Schütz
  • 517
  • 1
  • 7
  • 16
0
votes
1 answer

Ignoring characters in c++

I'm working on a hangman project for my final in my c++ class. In my game of hangman as long as a player keeps getting the right letters they'll their turn will keep going indefinitely until the get the word. Also in order to avoid the same letter…
user2340686
  • 97
  • 1
  • 3
  • 11
0
votes
3 answers

Combining two files full of numbers into a third, sorted file. Issue with filenames and cin

I have the following code... http://pastebin.com/KjzArbcg ^ Full code //the issue - this throws a Segmentation fault char *inname1 = "HW11F1.txt"; cin >> inname1; ifstream infile1(inname1); The assignment is the following.. "Write a program that…
Coty
  • 143
  • 1
  • 11
0
votes
2 answers

Is it possible to cout without overwriting current text in the input?

Okay, so let's say I have a program that couts a line while the user may be typing in information. For this example, let's say we're using the code cout << "THIS CODE IS BEING COUTED" << endl; Let's say for our example, the user is in the process…
user2980207
  • 293
  • 1
  • 11
0
votes
1 answer

Using getline to read either just a newline or text

So what I need to do is get input from a user, a filename specifically, with the alternative of the user just pressing enter to default to a certain filename. Here is what I have: cout << "Where should I save the exam (default exam.txt):…
user1111098
  • 287
  • 1
  • 3
  • 4
0
votes
3 answers

Why does this code involving cin skip getline even with cin.ignore()?

The following code works as intended for the first two getlines and after you input the CC variable it goes into an infinite loop skipping the getlines and not waiting for input. Here is a sample run: Enter card holder name (or quit): John Doe Enter…
Scholar
  • 293
  • 3
  • 8
  • 16
0
votes
1 answer

using cin.fail() for integer vs floor

I want to take user input and exit the program if the input is not integer. I checked a program from a book: http://homepages.gac.edu/~mc38/2013J/code/bookCode/ch03/elevator2.cpp It says that using cin.fail() I can check this. But program doesn't…
zud
  • 105
  • 2