![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Did you get any error messages? If not, open a command window and run your program from there, see what happens. Be clear and thorough in your posts.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#12 |
|
Newbie
Join Date: May 2006
Posts: 12
Rep Power: 0
![]() |
#include <iostream>
using namespace std; int main() { cout << "HEY, you, I'm alive! Oh, and Hello World!" << endl; cin.get(); return 0; } I changed the \n I know its good C++ practice to use it but I can type endl a lot faster than \n so thats what I walways use. Sometimes you have to put 2 "cin.get();" in there. I know I have to on most of mine to test. Change the return 1 to return 0 though. With this function, you dont need to return anything at all. I dont see why this should fail. OH I just thought of something. in my C++ IDE i have to have to have another include something like staffix.h or something.. Not sure what it is for since im just starting also. |
|
|
|
|
|
#13 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
>Try clearing the stream by using 'cin.sync();' before 'cin.get();'.
Um, no. cin.sync() isn't guaranteed to do anything meaningful, much less "clear" the stream. The only portable way to read and discard leftover characters is to read them either with a loop, or with cin.ignore(): // Loop char ch; while ( cin.get ( ch ) && ch != '\n' ) ; // Ignore #include <ios> #include <limits> cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#14 |
|
Newbie
Join Date: May 2006
Posts: 7
Rep Power: 0
![]() |
Okay, I tried what you said DaWai because I didn't get any error messages. I went to the command prompt, said start c:\learingc1.exe. I hit enter, then it went to asking for another command. It must have executed the file, but it appears that there is nothing happening. Is there anyway to cause it to pause.
and narue, i don't quite understand what you mean, you have to remember, I'm only in my first lesson of C++. |
|
|
|
|
|
#15 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
If you ran your program, as it is shown, in a commandd prompt window, and saw no output, then you probably have something that is not as shown. As far as endl is concerned, it outputs a newline and flushes the output buffer. There are conditions where the flush is a good idea, but they aren't often seen in these little "Goodbye, cruel world" programs. Still, doesn't mean you haven't something else running that's farbling with things.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#16 |
|
Newbie
Join Date: May 2006
Posts: 19
Rep Power: 0
![]() |
// My first program in C++.
#include <iostream> using namespace std; int main () { cout<<"Any text!"; return 0; } I have no problems like this.I also ran it the way you have posted with no problem.Try hitting the compile and run button. (f9)Last edited by JamesCEdmonds; Jun 1st, 2006 at 1:21 PM. |
|
|
|
|
|
#17 | ||
|
Hobbyist
Join Date: Sep 2005
Posts: 263
Rep Power: 4
![]() |
Quote:
Quote:
Just for reference: http://www.programmingforums.org/for...ead.php?t=6640 Won't be making that mistake again. ![]() |
||
|
|
|
|
|
#18 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
>Then told to use cin.sync(), and it "worked".
This is one of the grey areas. The C++ standard in no way implies that cin.sync() will do what most people expect when they want to "flush" the stream. Unfortunately, many compilers implement it so that it does, and even Stroustrup explicitly (and incorrectly) states that it flushes the stream. The best solution is to avoid it entirely in favor of other solutions that are guaranteed to work as expected.
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#19 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|