Problem with cin.get()

I wrote this simple program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

int main()
{
using namespace std;
char word[256];
char wordtoo[256];
cout << "Enter a word>";
cin.get(word,256);
cout << word << endl;
cout << "Other word>";
cin.get(wordtoo,256);
cout << wordtoo << endl;
return 0;
}


But when I build and run it, Other word> pops up and the program ends without giving me a chance to type anything. I'm never able to figure out how to use cin.get() more than once in any program.

Please help. (Please give code examples if you can.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

int main()
{
using namespace std;
char word[256];
char wordtoo[256];
cout << "Enter a word>";
cin.getline(word,256);
cout << word << endl;
cout << "Other word>";
cin.getline(wordtoo,256);
cout << wordtoo << endl;
return 0;
}

You should use cin.getline instead of get in that case...
Thanks! But is it impossible to use cin.get twice?
I have put it in my Compiler and this works just fine. And yes it is possible to use cin.get twice as well.
Last edited on
How? I'm using VC10 as my compiler. I tried g++ and I have the same issue
http://cplusplus.com/reference/iostream/istream/get/
If the delimiting character is found, it is not extracted from the input sequence and remains as the next character to be extracted
Topic archived. No new replies allowed.