Sign in to follow this  

No text output in console?

This topic is 4714 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
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

This topic is 4714 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this