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]
hanging newline
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:
string input;
while (getline(cin, input) && input != "quit")
{
// do whatever with input here
}
while (getline(cin, input) && input != "quit")
{
// do whatever with input here
}
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]
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]
: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
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
You know std::string has the member function c_str(), which returns a const char*? This way you can use strings in your new functions and still call the old ones.
---
Just trying to be helpful.
Sebastian Beschke
Just some student from Germany
http://mitglied.lycos.de/xplosiff
---
Just trying to be helpful.
Sebastian Beschke
Just some student from Germany
http://mitglied.lycos.de/xplosiff
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement