Getting a first basic "Hello World" program working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lvl 1 monk
    New Member
    • Nov 2009
    • 6

    #1

    Getting a first basic "Hello World" program working

    Hi all, I don't really have the money for the formal route so I went to the library and picked up an older c++ book and it seems I run into "antiquated headers" over and over again. The problem doesn't seem to be the headers though because I searched and skimmed over three other threads dealing with the same problem and none of which solved my problem.

    First and foremost, I have a copy of C++ Programming for the absolute beginner by Dirk Henkemans and I'm using Dev-C++ 4.9.9.2.

    That was the only free compiler I was able to find and this was the only book I was able to find besides the "for dummy's" iterartion, which thinking back might have been a good idea. But I digress, my problem is as follows:
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    int main()
    {
    cout << "Hello World!!!" ; //here is my error line
    return 0;
    }


    I'm not exactly sure what the problem is. More than a quick answer I'd really appreciate an explanation to the problem, hopefully in layman's terms because I indeed am a layman.

    Please?

    Any and all help will be greatly appreciated and any kind of guidance from here on out would be aweome! I've always wanted to learn, I just don't have the kinda money one needs for the equipment/programs.

    My name is Lenin Chavez and I hope to get to know the lot of you a lot better with time. Thanks again! endl;


    ps. was that $username thing when I first signed up a joke? it made me chuckle.
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    What does the error says????

    Regards
    Dheeraj Joshi

    Comment

    • lvl 1 monk
      New Member
      • Nov 2009
      • 6

      #3
      Funny enough the "error" is gone but now I just don't get a program to run. The DOS window jumps on the screen but I am not given an opportunity for any input as it just disappears once again and I'm taken back to the project screen.

      I guess my problem wasn't as severe as I first thought, now that I went back and cleared the code and re-wrote it in, but I still get no real confirmation to whether or not I did it right.


      Another thing, might you be able to explain to me the difference between having int main() vs int main(int argc, char *argv[])

      int main() is what the book is telling me should be there, but the latter is what the program is giving me.

      Sorry if I'm being too cryptic in my questions, I just really don't know what these things mean.

      Comment

      • Dheeraj Joshi
        Recognized Expert Top Contributor
        • Jul 2009
        • 1129

        #4
        Originally posted by lvl 1 monk
        Funny enough the "error" is gone but now I just don't get a program to run. The DOS window jumps on the screen but I am not given an opportunity for any input as it just disappears once again and I'm taken back to the project screen.
        It is because in your hello world program you are not taking any user inputs(I mean no cin >> is used......)

        And as far as command line arguments are concerned i.e int main(int argc, char *argv[] )

        Please do refer this link Command Line Argument and also google it... You will find plenty of stuffs...

        Regards
        Dheeraj Joshi

        Comment

        • lvl 1 monk
          New Member
          • Nov 2009
          • 6

          #5
          Originally posted by dheerajjoshim
          It is because in your hello world program you are not taking any user inputs(I mean no cin >> is used......)

          And as far as command line arguments are concerned i.e int main(int argc, char *argv[] )

          Please do refer this link Command Line Argument and also google it... You will find plenty of stuffs...

          Regards
          Dheeraj Joshi
          by this cin >> you mean to tell that it should read:
          Code:
          ...
          {
              cout << "Hello World!!!" >> ;
              return o;
          }
          is that what you mean?

          or

          Code:
          ...
          {
              cout << "Hello World!!!" ;
              cin >>;
              return o;
          }
          Please don't stamp me stupid for this post, I am super new to this. I realize I may be asking for a bit more help than might usually be provided here.

          and thanks for the link, I've been googling for something like this on google for two days now!

          Comment

          • mac11
            Contributor
            • Apr 2007
            • 256

            #6
            Your second one is almost the correct syntax for a cin, but you have to cin to some buffer:

            Code:
            #include <string>
            #include <iostream>
            
            using namespace std;
            
            int main()
            {
                string str;
            
                cout << "blah" << endl;
                cin >> str;
                
                return 0;
            }

            I added the "<< endl" to the cout statement to make sure your text actually displays. You can look it up later if you want. There are a lot of tutorials on this site for various things. I also take a lot of help from www.cplusplus.com

            Comment

            • Dheeraj Joshi
              Recognized Expert Top Contributor
              • Jul 2009
              • 1129

              #7
              Hi,

              cin >> takes the input from the keyboard. So your program is executing properly and DOS prompt disappears immediately because you are not making your program to wait for a keyboard input...

              You code may be like this:

              Code:
              void main( )
              {
                  cout << "Hello World" << endl;
                  getch();
              }
              getch() basically takes a character from keyboard...

              Regards
              Dheeraj Joshi

              Comment

              • lvl 1 monk
                New Member
                • Nov 2009
                • 6

                #8
                So I tried both of those that I presented before and the first one gave me: C++ Practice\hello world.cpp expected primary-expression before ';' token,
                where as the second one gave me:
                expected primary-expression before ';' token, twice

                Comment

                • Dheeraj Joshi
                  Recognized Expert Top Contributor
                  • Jul 2009
                  • 1129

                  #9
                  Originally posted by lvl 1 monk
                  by this cin >> you mean to tell that it should read:
                  Please don't stamp me stupid for this post, I am super new to this. I realize I may be asking for a bit more help than might usually be provided here.
                  Every programmer war once a newbie for any language.... So no one stamp you as stupid....

                  Njoy coding...

                  Reegards
                  Dheeraj Joshi

                  Comment

                  • Dheeraj Joshi
                    Recognized Expert Top Contributor
                    • Jul 2009
                    • 1129

                    #10
                    In which line you got the error?

                    Regards
                    Dheeraj Joshi

                    Comment

                    • lvl 1 monk
                      New Member
                      • Nov 2009
                      • 6

                      #11
                      Thank you guys once again, I'm sure this won't be the last time I pester the lot of you but I really appreciate what you guys are doing for me here. Thank you thank you thank you thank you. Both of the responses made crazy good sense and my most recent post before this one was made after your guys' responses so just ignore them. Once again thank you so much! :-D

                      Comment

                      Working...