No text output in console?

Started by
2 comments, last by pex22 19 years, 3 months ago
Hello I managed to compile my first C++ program last friday thanks to help from here, however, I does not succeed in getting my user conversation to work. I just need to get the standard CIN >> and COUT << to work for me. I have looked into "Simple File I/O Using C++" by John Peregrine, but I cant get it right. Any ideas? My main.cpp code looks like this: #include <cstdlib> #include <iostream> #include <iomanip> #include "MyClock.h" using namespace std; int main(int argc, char **argv) { MyClock k; int tt, mm, ss, p; cout << "Stall klockan !" << endl << "ange tim, min, sek" << endl; cin >> tt >> mm >> ss; k.stall(tt, mm, ss); cout << "Hur manga tick? " << endl; cin >> ss; for (int i=1; i<=ss; i++) k.myTick(); cout << "Klockan är nu "; k.myWrite(); system("PAUSE"); return EXIT_SUCCESS; }
Advertisement
What does it do wrong?

You should prolly ignore after you use cin.

cin >> input;
cin.ignore(80,'\n');//Make sure to stop getting input.

//Then do the
cin >> input2;
cin.ignore(80,'\n');

And also, if it doesn't show output properly. Then use cout.flush() after each cout << "Stuff" << endl;

Example:
cout << "Hello World!" << endl;
cout.flush();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                          
Looking for video game music? Check out some of my samples at http://www.youtube.c...ser/cminortunes            
                                                          
I'm currently looking to create music for a project, if you are interested e-mail me at cminortunes@gmail.com    
                                                          
Please only message me for hobby projects, I am not looking to create music for anything serious.
I included the flush and ignore thingings, but still not right.

When I execute the program, it just puts up a console window and asking me to push any key to continue. It does not perform any (at least none that I can see) of the cout/cin actions. Hard to debug, since I always use text output to follow the execution....

I have programmed quite a lot earlier, but only in Unix environment, but programming in windows environment seems to be more struggling with the OS than your own code. I guess that I'm trying to blame someone else for my own mistakes.

Can you see the text without MyClock?
(it seems like the answer to this question must be "Yes". if it is, then its probably in your clock class. maybe some memory i dont know.)
many compilers (like VC) are doing the system("PAUSE") after every program that was executed from the IDE.

Edit: Isn't std::cout portable (ANSI-C++)?
You can use most of the ANSI-C functions (e.g. printf, puts, scanf..) in console, if you did like to.
Ps. I said "most" but im not sure if random() and randomize() are ANSI-C, and if graphics is ANSI-C library. but they are available in Borland.

pex.
pex.

This topic is closed to new replies.

Advertisement