Archived

This topic is now archived and is closed to further replies.

conflict

hanging newline

Recommended Posts

oki, i am using char* strings, and i am reading in using cin.get(buf, 52); in a while game loop.. this work fine, until i input only a carried return/newline then the game loops in and out of my get_input function in a never ending loop O_o.. i have tried, cin.ignore, fflush, even a "dummy" cin.get(...) to catch it but these don't work. this is an example of what my code input code:
int main()
{
	char *str = new char[11];

	do
	{

		std::cout << "Enter text: ";
		std::cin.get(str,11);

	}while(strcmp(str, "quit") !=0);
	
	delete[] str;
	return 0;
}

  
please help :o thanks Lee [edited by - conflict on April 4, 2004 2:46:26 PM]

Share this post


Link to post
Share on other sites
OMG, hehe 10mins after posting i resolve it! \o/

cin.clear(); // because cin.get.. fails on CR \ \n.. cin state stays failed... thus b0rks, need reseting.
fflush(stdin); //flush hangline newlines.

love it

\o/

bah.. me thinks i gave up too soon

thanks
Lee

[edited by - conflict on April 4, 2004 3:07:38 PM]

[edited by - conflict on April 4, 2004 3:08:23 PM]

Share this post


Link to post
Share on other sites
:o

like i said, using char* (cstrings), which re vastly implemented throughout my game :o

tbh, i wish i had used std::string.. then i wouldn''t have to have sorted overflow issues...

but char * is good ptr practice

thanks
/me absorbs code :D

Share this post


Link to post
Share on other sites
jea i know c_str, so it can be used with legacy funtions..

but like i said, i have implemented char* through out me game, not gunna go _mess_ it up now by converting to std:string.

probably will use std::string in the future.

thanks
Lee

Share this post


Link to post
Share on other sites