Jump to content
  • Advertisement
Sign in to follow this  
Maskinchefen

No text output in console?

This topic is 4933 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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; }

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!