Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 32

Thread: C++ problem need your input

  1. #21
    Senior Member
    Join Date
    Sep 2001
    Posts
    1,027
    Originally posted here by invader

    urmm...doesnt getch() do the same ? Get a character from the user before continuing..
    Thanks anyway, ammo
    First, getch() isn't a standard call, and won't be availible on all systems; however, the standard C way of reading a single char from the standard input is getchar()
    (int getchar())
    which IS standard and can be found in stdio.h
    (#include <stdio.h> ).

    The exact equivalent with C++ streams would be:
    cin.get()

    both ways read a single char from the standard input and returns it...
    but since we're not interested in what that character is going to be (ie: we're not gonna use it), we might as well do a
    cin.ingore()
    as er0k mentionned previously.

    So both ways work, it's just a question of consistency:
    if you're using iostreams for IO (cin, cout...) in your C++ prog, you should stick with it and use cin.ignore(); or cin.get();
    if you're using stdio's (scanf(), printf()) you should stick with it and use getchar();

    Ammo
    Credit travels up, blame travels down -- The Boss

  2. #22
    Originally posted here by ammo


    First, getch() isn't a standard call, and won't be availible on all systems; however, the standard C way of reading a single char from the standard input is getchar()
    (int getchar())
    which IS standard and can be found in stdio.h
    (#include <stdio.h> ).

    The exact equivalent with C++ streams would be:
    cin.get()

    both ways read a single char from the standard input and returns it...
    but since we're not interested in what that character is going to be (ie: we're not gonna use it), we might as well do a
    cin.ingore()
    as er0k mentionned previously.

    So both ways work, it's just a question of consistency:
    if you're using iostreams for IO (cin, cout...) in your C++ prog, you should stick with it and use cin.ignore(); or cin.get();
    if you're using stdio's (scanf(), printf()) you should stick with it and use getchar();

    Ammo
    So basically, If Im using iostream, I have to type cin.ignore(); at the end of any program to see my
    output. Very cool Ammo.
    Light thinks it travels faster than anything but it is wrong. No matter how fast light travels it finds the darkness has always got there first, and is waiting for it.-Reaper Man

  3. #23
    Senior Member
    Join Date
    Sep 2001
    Posts
    1,027
    Well it's not that you *have to* to see your program's output: it's that when you lunch a console program in windows, when the progam ends, windows automatically closes the console window that was launched... adding cin.ignore() only delays the end of the program until user input. It's not really a programming issue of its own..

    If you were to start a command prompt first (run: cmd.exe (NT/2000) command.com (95/98)) the go to the directory you're program is in (cd c:\blah\blah) and then run it from there (myprog.exe), your prog would execute in that console window which would stay opened because it was opened manually (ie: not by the program itself)... (This was mentionned by shantz in his post)...


    Ammo
    Credit travels up, blame travels down -- The Boss

  4. #24
    Junior Member
    Join Date
    Dec 2002
    Posts
    8

    Re: C++ problem need your input

    Originally posted here by M/S Vin
    Hi, I'm a total beginner in C++. I am using Bloodshed Dev C-++ 4.01 Compiler. Now Im trying to get Hello World program to run, it compiles successfully but it won't Run. The command prompt blinks for one second and it disappears. Basically, it wont execute. I've enlist the help of Mathgirl but shes not too familiar with the compiler Im using, I've looked through this thread
    I followed it but it wont work.


    It's from the book teach Yourself C++ in 24 hours, although It'll take more than that.

    This is the program I did:

    #include <iostream>

    int main()
    {
    std::cout << "Hello World!\n";
    return 0;
    }


    It compiles successfully but like I said before it won't execute, I can't see the result Hello World. How do I get this simple program up and running? I appreciate any help.
    [ANSWER]
    Remove the space between include and <iostream>
    correct is:
    #include<iostream>
    [/ANSWER]

  5. #25
    Junior Member
    Join Date
    Nov 2002
    Posts
    3
    #include <iostream.h>

    int main()
    {
    cout << "Hello World ! \n" ;

    return 0 ;

    }

    This worked for me just fine,I really dont see what the problem is ?maybe it's your compiler or your typeing in the wrong command.

  6. #26
    Junior Member
    Join Date
    Dec 2002
    Posts
    8

    Re: Re: C++ problem need your input

    Originally posted here by djc314159

    [ANSWER]
    Remove the space between include and <iostream>
    correct is:
    #include<iostream>
    [/ANSWER]
    First I have to admit to an error, removing the space between <iostream> and include
    is not the answer. I've looked further into the problem and here's what I found.

    I'm running Windows xp and have the latest updates to both Windows and bloodshed c++.
    When I run the referred to program I get 70 compiler errors:
    typical error:
    In file iostream
    line 44 is bits/c++config.h, there is no such file or directory.

    Indeed when I looked at file iostream it does refer to bits/c++config.h which is nonexistant,
    however ming32/c++config.h does exist, hence all (or at least most) of the errors.

    I sent an bug report to bloodshed via a forum and am awaiting an answer. I'll report here what
    the say.

    Sorry for the error.

  7. #27
    Junior Member
    Join Date
    Dec 2002
    Posts
    8

    Re: Re: Re: C++ problem need your input

    Originally posted here by djc314159


    First I have to admit to an error, removing the space between <iostream> and include
    is not the answer. I've looked further into the problem and here's what I found.

    I'm running Windows xp and have the latest updates to both Windows and bloodshed c++.
    When I run the referred to program I get 70 compiler errors:
    typical error:
    In file iostream
    line 44 is bits/c++config.h, there is no such file or directory.

    Indeed when I looked at file iostream it does refer to bits/c++config.h which is nonexistant,
    however ming32/c++config.h does exist, hence all (or at least most) of the errors.

    I sent an bug report to bloodshed via a forum and am awaiting an answer. I'll report here what
    the say.

    Sorry for the error.
    I recieved a reply to my bug report.
    Their suggestions follow:

    Solution Number 1:

    Copy the files of C:\Dev-Cpp\include\c++\mingw32\bits

    to C:\Dev-Cpp\include\c++\bits

    Solution Number 2:

    Add C:\Dev-Cpp\include\c++\mingw32 to compiler/directories/C++ includes

    For more information:

    Goto the bloodshed forum: (use the about button to locate it)
    Search for 4.9.7.0
    Expand search: 4.9.7.0 BlackJak
    or 4.9.7.0 DerekBaker

    More: They reccommend trying solution 2 first since it's less intrusive.
    I'm going to proceed to try to fix my problem using these suggestions.
    In other words "physician heal thyself".
    I'll report on my progress or lack thereof.
    Remember, we're dealing with a Beta version and these kinds of problems
    should be expected, so be patient.
    Also, as they say "You get what you pay for".

  8. #28
    Junior Member
    Join Date
    Dec 2002
    Posts
    8

    Re: Re: Re: Re: C++ problem need your input

    Originally posted here by djc314159


    I recieved a reply to my bug report.
    Their suggestions follow:

    Solution Number 1:

    Copy the files of C:\Dev-Cpp\include\c++\mingw32\bits

    to C:\Dev-Cpp\include\c++\bits

    Solution Number 2:

    Add C:\Dev-Cpp\include\c++\mingw32 to compiler/directories/C++ includes

    For more information:

    Goto the bloodshed forum: (use the about button to locate it)
    Search for 4.9.7.0
    Expand search: 4.9.7.0 BlackJak
    or 4.9.7.0 DerekBaker

    More: They reccommend trying solution 2 first since it's less intrusive.
    I'm going to proceed to try to fix my problem using these suggestions.
    In other words "physician heal thyself".
    I'll report on my progress or lack thereof.
    Remember, we're dealing with a Beta version and these kinds of problems
    should be expected, so be patient.
    Also, as they say "You get what you pay for".
    Finally: I got my system to compile and run the subject program exactly as first reported.
    I used solution 2 above.
    I've detailed how I solved my problem in my latest journal entry.
    I'm not saying this is the only solution, or the best solution, but it is the one
    reccommended by BlackJak and it works for me.
    It's worth noting that original problem my be something different since it was
    originally reported that the system compiled ok but would not run. To run the
    compiled program you should be in a DOS window not the I.D.E.

  9. #29
    Senior Member
    Join Date
    Sep 2001
    Posts
    1,027
    It's really not the same problem as the original poster's... OP's problem was simply that it executed in a console window which closed immediatly after program ended.

    Ammo
    Credit travels up, blame travels down -- The Boss

  10. #30
    Banned
    Join Date
    Mar 2002
    Posts
    594
    Everyone keeps posting complicated functions that don't seem to work so try this simple one:

    #include <iostream.h>

    int main()

    {
    int x;

    cout << "Hello World!" << endl;
    cin >> x;

    return 0;
    }

    I started learning C++ not that long ago, 5/6 months to be exact, and I really like Bloodshed, not only cause its free but because its a got nice GUI.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •