Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Learning C++ with Dev-C++, Have basic questions

    My main problem with learning something without a teacher is that I cannot ask a lot of questions, which I'm sure will be answered later on in the online book I found...

    "http://newdata.box.sk/bx/c/htm/ch01.htm"

    (I added it, just incase you guys think that's a bad place to start. )

    Okay I honestly do not understand what errors I'm making when I'm following the instructions completely to the ++

    the book wants me to do this..

    1: #include <iostream.h>
    2: int main()
    3: {
    4: int x = 5;
    5: int y = 7;
    6: cout "\n";
    7: cout << x + y << " " << x * y;
    8: cout "\n";
    9:return 0;
    10: }

    When I type it in though and try to compile I get an error and..

    7 C:\Documents and Settings\math solution.cpp `cout' undeclared (first use this function)
    (Each undeclared identifier is reported only once for each function it appears in.)

    7 C:\Documents and Settings\math solution.cpp expected `;' before string constant

    9 C:\Documents and Settings\math solution.cpp expected `;' before string constant

    C:\Documents and Settings\Makefile.win [Build Error] ["math solution.o"] Error 1


    if it helps here a screen shot too.. lol yes I'm obsessed but I'm also obsessed with learning c++!

    http://i38.photobucket.com/albums/e1...in/Cerrors.jpg



    Now I think the main problem is because of the compiler I'm using, it may be too sophisticated for me to begin with, but then again it could be something else..

    if you guys can help..

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    You've included a header file, but you're not telling the compiler that you want to use cout. For that, you need to use the using statement. A quick workaround that probably shouldn't be used in production code is:
    Code:
    using namespace std;
    Place it right after the include.

    The tutorial you're following doesn't mention this at all, which suggests either it's not really meant for someone starting from scratch, or it's incomplete and will mess with your head.

    oracleguy jumps into lots of the c/c++ threads here, so maybe he'll have an idea of a good book or online resource for you. I've not done any c/c++ since completing my degree.

    EDIT: You may also need to change from the older c-style header (iostream.h) to the cpp style (iostream). Not sure on that. I had to do it here for testing.
    Last edited by tomws; 11-02-2009 at 03:30 PM.
    Are you a Help Vampire?

  • #3
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thank you for that insight, I guess I better look around for something else. I added the using namespace std; but it still brings up the same error, and I have no idea why.

    Lol I have no idea what a namespace std; is either. I wish there was a C++ book that would just take the first few chapters and explain what everything is and does that I will be using.. ugh..

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by demoneyejin View Post
    I wish there was a C++ book that would just take the first few chapters and explain what everything is and does that I will be using.. ugh..
    Considering that C++ is one of the most robust application development languages, you'd probably give up before ever getting to the coding portion of the book. A mixture of simple code and explanation is usually best. The one you're using is flawed, that's all.

    We used the Deitel textbook for C++ when I was in school. You can probably pick up an older version cheap on Amazon. I just checked, and the old version 5 we used is available from $17. Search for ISBN 0131857576.

    What does your current code look like and what is the latest error? We can help debug what you have now.
    Are you a Help Vampire?

  • #5
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ah Yeah, Lol Broke and jobless, can't spend money Gotta use my online resources!

    I have a lot of free time and I don't plan on giving up any time soon, I've got a lot of patience and am willing to do whatever to learn the concepts etc. I just get frustrated that I can't get past day 1 on that tutorial haha, makes me feel dumb.

    Currently this is what I have..


    http://i38.photobucket.com/albums/e1.../Cerrors-1.jpg

  • #6
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    On line 9 you have:

    Code:
    cout "\n";
    Should be:

    Code:
    cout << "\n";
    Note the << operator.

    EDIT: Also on line 11.
    Are you a Help Vampire?

  • Users who have thanked tomws for this post:

    demoneyejin (11-02-2009)

  • #7
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Yarr!! it worked! neatttt so awesome. I love this whole programming thing. I hope you don't mind but I have a million questions now lmao..

    #include <iostream>( this is a header)

    using namespace std;( what's this?)

    int main()( this is a function..right? why do functions need a "()"?)

    {
    int x = 5;( integer)
    int y = 7;(integer)
    cout << "\n"; (what does cout stand for? I know it has to do with output?)
    cout << x + y << " " << x * y;
    cout << "\n";
    return 0; (returning something means to end the function, right?)
    }

  • #8
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    The using namespace std; tells the compiler what components you want to use from the header file. In this case, you're telling it you want everything. Good, old programming 101 (and probably good programming practice) would have you rather specifically list your requirements so you don't suffer from code bloat. Since you're using cout, the syntax would be, as I recall:
    Code:
    using std::cout;
    I'm not a C coder, though, so maybe someone can clarify the details here.

    As for what cout means, I think it's "console output".

    Functions use parentheses to allow arguments to be passed in for processing. You'll get to those in a few lessons, I suspect.

    And, yes, return means, more or less, that's the end of the function. What it does is to return the value to the caller. For the main function, it's the program's return value. Useful for determining success/failure.
    Are you a Help Vampire?

  • #9
    New Coder
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Haha, thanks man. You've def helped me a lot today. I can finally make it to day 2 of this e-book until I find something better to go by.

  • #10
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by tomws View Post
    The using namespace std; tells the compiler what components you want to use from the header file. In this case, you're telling it you want everything. Good, old programming 101 (and probably good programming practice) would have you rather specifically list your requirements so you don't suffer from code bloat. Since you're using cout, the syntax would be, as I recall:
    Code:
    using std::cout;
    That is pretty close. The using namespace std; means you want to include everything in a namespace called 'std'. And a namespace can span more than one header file. All the standard C++ library stuff is in that namespace. As for what namespaces are, I'd suggest this link: http://www.cplusplus.com/doc/tutorial/namespaces/

    And tomws is correct about the using std::cout;. In production code you would want to avoid bringing in the whole namespace, only bring in stuff as needed.
    OracleGuy


  •  

    Posting Permissions

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