error with cin.get()

the error is that it skips past it in the console and goes to the end, this is the form it was in directly out of the book im using, im using the GNC GCC compiler in CodeBlocks,what am i doing wrong? Also is there any way to search the forums, the search thing only searches arcticles and references i think...

here is code:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;
int main()
{
	char buffer[80]={'\0'};
	cout << "Enter a string: ";
	cin.get(buffer,79);
	cout << "Here is the buffer: "<<buffer<<endl;
	return 0;
}
why use cin.get at all?

i would sugest to do this:

cin >> buffer;

but i havent really looked into the cin.get to be honest so i dont really know,
Is your program that the console window is closing before you have time to see the output. You can probably configure your IDE or change some settings to make the window stay after the program has ended. There is actually a sticky thread about this issue http://cplusplus.com/forum/beginner/1988/ (not that it's very good).
oh, i kinda misunderstood the opening post then :(
and once again peter corrects my mistakes haha.

ya there are several ways to have the window stay up after the program is done, like system("Pause"); (which shouldnt be used if you are gonna distribute your code or program, since it is slow, and i think its windows specific)

and that thread must surely be the longest thread i have ever seen on such a simple topic :P
I can see it just fine, the problem is... it goes to the point where it would accept input, then immediately skips past it, then its press any key to continue (i.e. end program). im wondering why it skips pas it like it does, by the way why doesn't the forum email you when threads are updated?
can someone post code that works, that uses cin.get(), with the GNC GCC compiler so we can cross reference them or something. The thing im most worried about is the possibility that the compiler is the problem...
Topic archived. No new replies allowed.