Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with cin.getline 1

Status
Not open for further replies.

SpeakerForTheDead

Programmer
Jan 31, 2002
28
US
I'm trying to write a program that frequently prompts for char arrays. I've been told to stay away from the gets function. Yet when I run the progam, it does something very strange. It skips the cout command that precedes it and then displays the text AFTER the prompt. And there are other problems that arise later in the program. It is not a problem that lies elsewhere in the code. I've done the program on a different system using strings. Is there another alternative?
 
I'm sorry. There's probably nothing wrong with cin.getline.

The same thing is happening with getch.

It's something SERIOUSLY wrong with my compiler. I'm going to try reinstalling it.
 
It has nothing to do with your compiler,the problem it's with the function "cin.getline", can you post the part of the code that you are having problems with ?
 
I figured it out. I was using "/n" instead of endl and that was screwing up cin.getline and getch

Now I've got a few more problems, but those should be easy. Just one question. How can you determine if a file already exists? The function always returns that that the file exists, even when it doesn't.
 
Ok,try this:

bool fExist( char* filename )
{
WIN32_FIND_DATA file;
HANDLE hFile;
if (( hFile = FindFirstFile( filename,&file ))
== INVALID_HANDLE_VALUE )
{
return false;
}
return true;
}
 
I am having a similar problem to that of Speakerforthedead, when i use cin.getline this step is either skipped (string is randomly set or something) or hitting return won't help. i was using something like cin.getline(name[x],100,'\n'). When i read this forum i tried endl but that doesn't work either. I just get a loop where its blank and i can't get to the next step in my program. If anyone could help that would be great. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top