| | |
How do I flush the input stream?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
>Again if anyone knows why I'm getting the compile error posted above when
>using g++ in linux (ubuntu) would you please help me out?
I had nothing better to do, so I decided to screw around with the code Narue posted. You're correct in that g++ gives an error when compiling the 'pause' class. Try renaming the entire 'pause' class to something else, perhaps pause2 (in other words, do an entire find and replace with 'pause'), and it'll compile fine. I asked Narue about this on IRC, and she figured it was probably some gcc/g++ extension that was messing things up (which is obviously the only real possibility here).
>using g++ in linux (ubuntu) would you please help me out?
I had nothing better to do, so I decided to screw around with the code Narue posted. You're correct in that g++ gives an error when compiling the 'pause' class. Try renaming the entire 'pause' class to something else, perhaps pause2 (in other words, do an entire find and replace with 'pause'), and it'll compile fine. I asked Narue about this on IRC, and she figured it was probably some gcc/g++ extension that was messing things up (which is obviously the only real possibility here).
Last edited by John A; May 26th, 2008 at 7:52 pm.
"Technological progress is like an axe in the hands of a pathological criminal."
•
•
Join Date: Mar 2008
Posts: 25
Reputation:
Solved Threads: 0
Thank you John A and Narue.
I never would have thought of something like that since I'm a noob. I don't know enough to decide between windows, linux and the different compilers who is complying with c++ standards and who is not fully compliant. You are a real help.
Thanks for the hard work coding this and thanks for looking into my g++ problem.
I never would have thought of something like that since I'm a noob. I don't know enough to decide between windows, linux and the different compilers who is complying with c++ standards and who is not fully compliant. You are a real help.
Thanks for the hard work coding this and thanks for looking into my g++ problem.
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
> ...probably some gcc/g++ extension that was messing things up
> (which is obviously the only real possibility here).
it is not some gcc/g++ extension; it is POSIX
> (which is obviously the only real possibility here).
it is not some gcc/g++ extension; it is POSIX
man pause http://node1.yo-linux.com/cgi-bin/ma...ommand=pause(2) Last edited by vijayan121; May 27th, 2008 at 2:39 am.
That's why Edward puts as much code as possible in namespaces. Compilers are bad about including all kinds of unexpected stuff in the standard headers, so even if you don't include unistd.h yourself, iostream or another standard header might do it for you and create a name conflict.
If at first you don't succeed, keep on sucking until you do succeed.
•
•
Join Date: Mar 2008
Posts: 25
Reputation:
Solved Threads: 0
I can not find unistd.h anywhere on my system.
So let me see if I understand this.
POSIX is the linux API just like there's a Windows API.
By changing pause to pause2, we have something that complies to c++ standards, Windows API standards, and POSIX standards.
Is that how it works? I guess just learning c++ will not be enough if I want to program cross platform?
Is one or the other of the above mentioned not 100% following standards or is that just the way it works?
Sorry so many questions but I don't understand this type of issue yet. Tell me if I'm way off in my way of thinking. Is this even a standards issue or something else?
Thanks
So let me see if I understand this.
POSIX is the linux API just like there's a Windows API.
By changing pause to pause2, we have something that complies to c++ standards, Windows API standards, and POSIX standards.
Is that how it works? I guess just learning c++ will not be enough if I want to program cross platform?
Is one or the other of the above mentioned not 100% following standards or is that just the way it works?
Sorry so many questions but I don't understand this type of issue yet. Tell me if I'm way off in my way of thinking. Is this even a standards issue or something else?
Thanks
Don't know how useful this is to anyone else, but I made a pdf set up for easy reading on my Irex Iliad digital book reader. I'm sure some of you have some Kindles or Sony Readers or whatever.
Anyway, here you go, my pdf I made of Narue's post. (By the way if you feel this is in some way a violation of your work feel free to remove it)
Anyway, here you go, my pdf I made of Narue's post. (By the way if you feel this is in some way a violation of your work feel free to remove it)
I would love to change the world, but they won't give me the source code
•
•
Join Date: Dec 2008
Posts: 12
Reputation:
Solved Threads: 2
C++ string and getline are your friends so get to know them well
There are some minor differences between Linux and Windows which I have documented. For input tests 1, 4, & 5 I used:
abc
for the 1st input.
CPP Syntax (Toggle Plain Text)
// flushinput.cpp // A test program to test flushing input specifically cin // Last Modified: 20081208 #include <iostream> #include <fstream> #include <string> #include <iomanip> #include <exception> #include <stdexcept> #include <new> using namespace std; int main() { cout << "flushinput" << endl; cout << "A test program to test flushing input specifically cin." << endl; string input1 = ""; string input2 = ""; cout << endl; cout << "There are 5 input tests:" << endl; cout << "1. Type 1 or more characters and then press Enter." << endl; cout << "2. Just hit Enter(don't type any characters, just press Enter)." << endl; cout << "3. Signal EOF(don't type any characters, Linux - just press Ctrl+D. Windows - just press Ctrl+Z and then Enter)." << endl; cout << "4. Type 1 or more characters and then Signal EOF and then press Enter(Windows - press Enter a second time)." << endl; cout << "5. Type 1 or more characters and then Signal EOF twice(Windows - press Enter twice after signalling EOF twice)." << endl; cout << endl; cout << "Correct solution would be that the program waits for you to enter the 2nd input regardless of what you entered for the 1st input." << endl; cout << "Incorrect solution would be that the program finishes without asking for the 2nd input." << endl; cout << endl; cout << "Enter 1st input: "; getline(cin, input1); cerr << endl;// Input tests 1 - 5: L - Linux, W - Windows L L L L LW cerr << "cin.bad()=" << cin.bad() << endl;// Results: 0 0 0 0 00 cerr << "cin.eof()=" << cin.eof() << endl;// 0 0 1 0 10 cerr << "cin.fail()=" << cin.fail() << endl;// 0 0 1 0 00 cerr << "cin.good()=" << cin.good() << endl;// 1 1 0 1 01 cerr << "input1.size()=" << input1.size() << "!" << endl;// 3 0 0 3 33 if(!cin.good())// Input tests 3(Windows & Linux) & 5(Linux only) put cin into an error state. { cin.clear();// Reset the cin status flags to their default. } cout << endl; cout << "Enter 2nd input: "; getline(cin, input2); cout << "Program finished." << endl; return 0; }
There are some minor differences between Linux and Windows which I have documented. For input tests 1, 4, & 5 I used:
abc
for the 1st input.
![]() |
Similar Threads
- Do/While Loop help (C++)
- convert lower case letters to uppercase and vice-versa (C++)
- overloaded input stream help (C++)
- Noob : Input Stream Trouble (Java)
- string input not working as expected (C++)
- Print_Zero Function (C)
- Question:: reading from an input stream. (C++)
- How do I pause a Prorgam? (C++)
Other Threads in the C++ Forum
- Previous Thread: OpenPictureDialog killing LoadFromFile
- Next Thread: CalcOpticalFlowBM function in OpenCv
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





