• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ programmers, help a newb!

RaynorWolfcastle

Diamond Member
What is the command to pause the system until the user presses a key?
I only need this at the end of my (very simple) program. VS 6 used to do it alone, but VS.NET doesn't.

I've used the getch() function, but for some reason, it screws with my cout statements.

Can you please help?

-Ice
 


<< why dont you just
string dumb;
cin>>dumb;
>>



because then the user has to press return. Unfortunately, I don't know the answer to this.
 
I could do that, but it seems so unelegant (is that a word?) and the user has to hit enter. I want something that will just pause until hits any key.

Side question, is there any way to get a cout.width statement to last for more than 1 cout?

-Ice
 
getchar();

should work so that you only need to press a key.
As with all C functions, you can ignore the return value (a char).
 


<< getchar();

should work so that you only need to press a key.
As with all C functions, you can ignore the return value (a char).
>>



getchar() gives me an undeclared indentifier error, which header file do I need to include?

Is getchar() the same as getch() ? because getch() causes problems with my cout statements (don't ask me why)

-Ice
 
#include <stdio.h>

Sorry, it's a standard line in my programs, forgot to give it to you.

Edit: getch and getchar are two different commands, and only getchar is really supported in VS6 and VS.NET
 
I am incredibly stumped, I see the things appear, AFTER the commands but the getchar() or cin.ignore() are the last things in main. 😕 😕 😕
*edit* using 2 cin.ignores works but there is nothing between them and I only have to hit enter once 😕

-Ice
 


<< I am incredibly stumped, I see the things appear, AFTER the commands but the getchar() or cin.ignore() are the last things in main. 😕 😕 😕
*edit* using 2 cin.ignores works but there is nothing between them and I only have to hit enter once 😕

-Ice
>>



I might have an idea what you're doing wrong. cin is getting messed up because it's not pulling the newline character at some point. Post your code and I might be able to point out where. You may have to use a cin.clear() (I think that's the function, don't quote me on it).
 


<< #include "windows.h" (i think)

system("PAUSE")
>>



This works well, but displays "Preass any key to continue..." on the screen. I don't think it's in windows.h though.
 


<<

<< #include "windows.h" (i think)

system("PAUSE")
>>



This works well, but displays "Preass any key to continue..." on the screen. I don't think it's in windows.h though.
>>

Why wouldn't you want the "Press any key to continue..." message? If it doesn't show up the person could sit there waiting for teh program to end.

Chris: Dump the intro to your site. It's pretty ghey (all intros are, not singling you out)
 


<<

<< #include "windows.h" (i think)

system("PAUSE")
>>



This works well, but displays "Preass any key to continue..." on the screen. I don't think it's in windows.h though.
>>



You need to include <process.h> or <stdlib.h> to use it.
 
Well, I went to see my prof today and he explained what the problem was. Apparently it has something to do with the way cin works. He explained to me how to use cin.clear() to remedy the solution. Thanks to all that offered help. I fixed the link in case any of you want to see what the source file looked like anyway.

-Ice
 


<< Chris: Dump the intro to your site. It's pretty ghey (all intros are, not singling you out) >>



Yeah, I'm in the process of updating my site, that's one thing I'm getting rid of. Well not quite, I'm keeping it somewhere insde the site to show that I have some Flash skills. But it's gone from the front page. 🙂

-Ice
 


<< Well, I went to see my prof today and he explained what the problem was. Apparently it has something to do with the way cin works. He explained to me how to use cin.clear() to remedy the solution. >>



Told ya. 😉 Glad you got it working. The code wasn't that hard to understand despite the lack of comments 🙂
 
Back
Top