What am i doing wrong

This is a discussion on What am i doing wrong within the C++ Programming forums, part of the General Programming Boards category; Here is the source code Code: #include <iostream.h> #include <stdlib.h> void demonstrationfunction() { cout "hello\n"; } int main() { system("PAUSE"); ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    2

    What am i doing wrong

    Here is the source code


    Code:
    #include <iostream.h>
                #include <stdlib.h>
    
                void demonstrationfunction()
                {
                 cout "hello\n";
                }
    
                 int main()
                 {
    
                 system("PAUSE");
                 return 0;
                 }

    When i compile it it says that something is wrong In function`void demonstrationfunction()':
    parse error before string constant

  2. #2
    Registered User
    Join Date
    Jan 2004
    Posts
    10
    cout is used like this:

    cout << "text you want out";

    It's base things.Might wanna look up a tutorial.
    #include "Sig.h"
    #ifndef noob
    #define noob keybone
    #endif

  3. #3
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124
    Code:
    #include <iostream>
    using std::cout;
    #include <stdlib.h>
    This isn't needed
    
                void demonstrationfunction()
                {
    cout is not complete. You need the insertion operator.
                 cout << "hello\n";
                }
    
                 int main()
                 {
    You have to call the function for it to be able to do anything. Add in:
                 demonstrationfunction();
                 system("PAUSE");
                 return 0;
                 }

    Try and see if it works now.

  4. #4
    Registered User
    Join Date
    Jan 2004
    Posts
    2

    Post

    Thanks for help cyberclown.I have readed the basic in c++ but now i need some more advanced tutorials

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    functions are still very basic C++... and if your going to use <stdlib.h>, I suggest you use <cstdlib> instead... newer standards... and system("pause"); isn't very portable... I would use something like this:
    Code:
    ...
    std::cout<<"Press any key to continue . . .";
    std::cin.get();
    ...
    or
    Code:
    #include <conio.h>
    ...
    std::cout<<"Press any key to continue . . .";
    getch();
    ...
    I'm not too sure about the portability of the second one though... I just like it better because it doesn't wait for a \r...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,157
    Originally posted by major_small
    ... and system("pause"); isn't very portable... I would use something like this:
    Code:
    #include <conio.h>
    ...
    std::cout<<"Press any key to continue . . .";
    getch();
    ...
    I'm not too sure about the portability of the second one though... I just like it better because it doesn't wait for a \r...
    It isn't. getch() is a great function iff you have it defined in your compiler, but most compilers don't.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I've been able to use it in every compiler i've used...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I've been able to use it in every compiler i've used...
    That isn't an excuse. When we speak of portability, we mean every compiler on every platform that supports C++. You should know by now that the "works for me" approach to programming is fraught with peril...mostly the peril of us telling you that you're an idiot. Anyway, to correct your code:
    Code:
    std::cout<<"Press any key to continue . . .";
    std::cin.get();
    C++ input is line oriented, which means the program won't continue until a newline is entered. So the prompt should be changed to
    Code:
    std::cout<<"Press return to continue . . .";
    std::cin.get();
    My best code is written with the delete key.

  9. #9
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,157
    Originally posted by major_small
    I've been able to use it in every compiler i've used...
    Unless you've tried all 137 compilers, so what? I've used compilers they haven't worked on. And I'll bet Salem, Prelude, Hammer, and many others have too. Ignorance of other options is dangerous. And you've been around these boards long enough to know getch() is NOT standard. It's nice to suggest using the "newer standards" but don't ignore the old standards.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    >>Unless you've tried all 137 compilers
    you've counted? :rolleyes:

    prelude: I know... I usually use cin.get and put "press return to continue . . ."

    >>It's nice to suggest using the "newer standards" but don't ignore the old standards.
    what do the 'old standards' have to offer that the newer standards don't cover when it comes to using cstdlib?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

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