I cant do it but its in the tutorial

This is a discussion on I cant do it but its in the tutorial within the C++ Programming forums, part of the General Programming Boards category; >> Dont really need the <<endl; thing It will flush the buffer, which should be done before the cin.get() call, ...

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> Dont really need the <<endl; thing

    It will flush the buffer, which should be done before the cin.get() call, but you never know. That code should work on that compiler, so we are all just guessing. The return 0, on the other hand, shouldn't make any difference.

  2. #17
    Registered User
    Join Date
    Dec 2005
    Posts
    15
    SERIOUSLY: AFTER you see the 13 outputted on the screen, do you type 13 and then press enter??! cuz if you don't, THAT'S the problem--you should!!! lol

    the problem is simple, and it doesn't have anything to do with the code but with the level of comprehension of the code form the "coder's" part.
    the cout<<"13"; line is clearly the source ...but what none thought to ask clearly out of the nice young lad here is whether he actually inputs anything after he sees "13" outputted on the screen, when running the program. i think he doesn't. he gets discuraged by the 13 already there, thinks there's something wrong with the code, and doesn't input the age...thus, nothing happens.

  3. #18
    Registered User
    Join Date
    Jan 2006
    Location
    enumclaw wa
    Posts
    5

    WHOA thnx

    Yeah I wan't typing in 13 and pressing enter I just did it. AND IT WORKED!!! Thnx for all the help guys and I will continue replying. Oh yeah and I had a typo it is 4.9.9.2 and not 4.9.92 srry
    Last edited by milesmiles; 01-31-2006 at 04:48 PM.

  4. #19
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    >> Dont really need the <<endl; thing

    It will flush the buffer, which should be done before the cin.get() call, but you never know.
    cin is linked with cout (I forget the exact term), so that whenever you call cin, cout is flushed.

    Why do you think this works?
    Code:
    #include <iostream>
    
    int main(void) {
        std::cout << "Enter a number: ";
    
        int n;
        std::cin >> n;
    
        return 0;
    }
    You would think cout wouldn't be flushed, and it wouldn't print the prompt. But it does.

    If you want to flush a stream without printing a '\n', use flush:
    Code:
    cout << "Reading from file" << flush;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #20
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    If Anyone cares, this, I think, is better than system("Pause");

    system("pause>nul");

    That way it does't display the anoying "press any key to continue. . ." message. I know that isn't what you guys are talking about, but hey!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My new website
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-17-2006, 06:38 PM
  2. Cprog tutorial: Design Patterns
    By maes in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2004, 01:41 AM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM
  4. Problem with tutorial (Vector class)
    By OdyTHeBear in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2002, 01:49 PM
  5. My DirectInput tutorial....
    By jdinger in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-18-2002, 11:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21