1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Beginning C++, got stuck immediately!

Discussion in 'C++' started by grandmasterk, Apr 17, 2007.

  1. grandmasterk

    grandmasterk New Member

    Joined:
    Apr 17, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I'm doing a C++ video tutorial. They tutors are using Visual Studio 2003, I'm using Visual Studio 2005. Compiling the code just below worked fine for them:


    Code:
    #include <iostream>
    
    main[]
    {
    	std;;cout << "Hello World!" << std;;endl;
    }
    When I tried to compile it I get this error:

    Code:
     end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

    I don't know what any of this stuff means yet but my C++ project is a Win32 Console Application.
     
    Last edited by a moderator: Apr 17, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    main [] should be main()


    [comment]Upi had the quote block where as it should be code block.[/comment]
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Not only should main [] be main (), main should be declared to return an int. C++ does not support main as a void type, nor does it support an implicit type of int. If your compiler does, it is non-compliant in that respect.

    Code:
    int main ()
    {
       ...
    }
    
    Furthermore, the correct syntax is std::cout, NOT std;;cout. This may be a great tutorial, but you need a copy of the material that you can SEE and some other tutorial information that you can READ.

    All that is not the seat of your current problem, however. You need to go to Project/Properties/Configuration Properties/C C++/Precompiled Headers and select "Not using precompiled headers". Then delete all references to stdafx as well as stdafx.h.
     
  4. grandmasterk

    grandmasterk New Member

    Joined:
    Apr 17, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Wow very good help indeed, better then I was hoping for. Before I continue the lessons can you tell me why it worked for them and not me? It's startng to feel like I'm end up getting alot of that from the tutorials and maybe should find something else to learn from. ($100 well spend it seems.)

    Code:
    #include <iostream>
    
    int main()
    {
    	std::cout << "Hello World!" << std::endl;
    }
    
    after doing your "not using preomciled headers" steps, that code worked as far as Building. Build Soluttion succeeded. However, Build HelloWorld is the samething as clicking run, yes? (HelloWorld is the title of the project). For them it opens up that DOS window and says Hello World and press any key to continue. Nothing happens when I click Build HelloWorld, except some of that stuff in the output box that tells me it was succesful?

    Code:
    1>------ Build started: Project: HelloWorld, Configuration: Debug Win32 ------
    1>Linking...
    1>Embedding manifest...
    1>Build log was saved at "file://c:\Documents and Settings\Allen\My Documents\Visual Studio 2005\Projects\HelloWorld\HelloWorld\Debug\BuildLog.htm"
    1>HelloWorld - 0 error(s), 0 warning(s)
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
    Really appreciate the help, this is the fourth time in the last 5 years I've attempted to start learning C++ and each time I pretty much ran into a wall right at the beginning and was forced to give up.
     
    Last edited by a moderator: Apr 18, 2007
  5. grandmasterk

    grandmasterk New Member

    Joined:
    Apr 17, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Apologies, I forgot the code block again.
     
  6. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Build is not the same thing as run. Build rebuilds the program from scratch. This means:

    1. Each source file (you may have more than one) is
    a. preprocessed
    b. compiled

    2. All resulting object files are linked into an executable.

    T-T-t-t-t-hat's a-a-a-a-l-l-l-l f-f-f-f-olks. If you want to run it, do so.

    You need to do two things: continue your studies; learn your tools. I doubt seriously that you would buy plans for a gazebo and buy a couple K worth of power tools and start in without reading both the plans AND the manuals for the tools. If you would, don't call me to donate extra fingers for you. Don't do it in programming, either. Your tool (the compiler/IDE) has help files. Use them.
     
  7. grandmasterk

    grandmasterk New Member

    Joined:
    Apr 17, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    by the way, the configuration manager says Configuration is in Debug mode, is that right? I switched it over to Release to see what that would change and then I started getting that same error from the first post again so I brought it back to Debug.
     
  8. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Like I said, read your help files. They explain debug versus release mode.

    Let me say something else: perhaps this is a game to you, like playing Mario II, or something. If it is, have fun. In the real world it is not a game. It produces things which advance the progress of mankind. Perhaps one percent of professionals, even, get this.

    This stuff is used to build intravenous infusions pumps. If you **** around, someone dies. Astronauts don't get home. Less importantly, mail doesn't get delivered. I hope you get the picture.
     
  9. grandmasterk

    grandmasterk New Member

    Joined:
    Apr 17, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    not in the slightest.
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Edited again. I think we should have a code block in the Quick Reply as well. Dont you think that will help. I am not a JS expert and so lets hope I can do that.
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    We have that now in place. In Quick Reply to have the Code / HTML / PHP code block.
     
  12. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Excellent.
     

Share This Page