Thread: endl;

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Monrovia, Los Angeles County, California
    Posts
    46
    Rep Power
    12

    endl;


    Alright, Im reading that 'Teach yourself C++ in 21 days' online book, and i have a question that i'm sure one of you can answer. I have the code which looks like this:

    Code:
    1:     // Listing 2.2 using cout
    2:
    3:     #include <iostream.h>
    4:     int main()
    5:     {
    6:        cout << "Hello there.\n";
    7:        cout << "Here is 5: " << 5 << "\n";
    8:        cout << "The manipulator endl writes a new line to the screen." <<  endl;
    9:        cout << "Here is a very big number:\t" << 70000 << endl;
    10:       cout << "Here is the sum of 8 and 5:\t" << 8+5 << endl;
    11:       cout << "Here's a fraction:\t\t" << (float) 5/8 << endl;
    12:       cout << "And a very very big number:\t" << (double) 7000 * 7000 << endl;
    13:       cout << "Don't forget to replace Jesse Liberty with your name...\n";
    14:       cout << "Obscurity is a C++ programmer!\n";
    15:        return 0;
    16: }
    Now, We are looking at line 8, and when I try to compile it I get an error. So im wondering if there has to be something before you can use the endl; endings...Or something similar, any ideas?
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    looks fine to me, what is the error u r recieving?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Monrovia, Los Angeles County, California
    Posts
    46
    Rep Power
    12
    Odd, instead of making it just a source file and then compiling...I made it a project and it worked without flaws. Does this happen to make a difference?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Hi,

    First of all, I tried to learn C++ from that book, which I bought, and it's horrible. You're never going to learn C++ in 21 days, so forget it--especially with that book, but feel free to ask all the questions you are going to have with that book as a tutor. Just remember: don't ever trust anything it says. If you don't understand something, it is most likely the book that is wrong or confusing, not your thinking process.

    It sounds like you're using VC++ for your compiler. For every program you create, you need to start off by creating a project. Then you creat a source file inside the project for your program. Click on New and the Projects tab should be selected. Then select Win32 Console Project, give your project a name, click on OK. Select empty project, click on Finish, and click on OK.

    To create a source file in your project, click on New again. This time the Files tab will be selected. Click on C++ source file, give it a name, and click on OK. Then you're set to go.

    There is one other thing called a "project workspace." The project workspace is the folder in which everything related to the project is stored. It has an extension .dsw. When you want to work on a project(i.e. your program), you need to open the project workspace using the File menu item, and your project will be displayed along with it's source file.

    The hierarchy is: the project workspace contains your project which contains your source file. You can delete a file out of your project by highlighting it in File View, and hitting the delete key, but it will still exist in your project folder, so you won't be able to make a permanent mistake. After you delete a source file from your project, if you minimize VC++ and navigate to the folder containing your project, you''ll notice that your source file will still be there. If you delete it out of the folder, then it will be gone permanently--actually then it will still go to your recycle bin. Kind of complicated, eh?
    Last edited by 7stud; March 21st, 2003 at 10:34 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Monrovia, Los Angeles County, California
    Posts
    46
    Rep Power
    12
    Im working with Dev-C++ compiler.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    lol, never mind.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Monrovia, Los Angeles County, California
    Posts
    46
    Rep Power
    12
    Do you have a better online reference manuel? Im looking just for at least the basics, until I can get better and better at it.
  14. #8
  15. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,171
    Rep Power
    2222
    Originally posted by Obscurity
    Do you have a better online reference manuel? Im looking just for at least the basics, until I can get better and better at it.
    The Dev-C++ IDE should have a help file for using the IDE. Plus, the Dev-C++ resources include a GNU C Library Reference, though you will need to use the Package Manager to install it and I found that version 4 doesn't let you install packages.

    I installed Dev-C++ nearly two months ago. However, I rarely use the IDE, but rather have been using their MinGW compilers from the command line. I'm also studying Linux systems programming and this approach is almost identical between the two.

    Add the Dev-C++ bin directory to your search path. The C++ compiler is g++ (gcc is the C compiler). It not only compiles source code, but it also links object files and libraries and creates an executable. The command to create an executable, prog.exe, out of the source files src1.cpp and src2.cpp, linking in the libwsock32.a library and displaying all warnings and errors would be:
    g++ -Wall -o prog src1.cpp src2.cpp -lwsock32

    If you leave out the -o option, then the executable name defaults to a.exe (a.out under Linux).

    Ideally, you would define your program with a makefile and run make on it, but the command line invocation should work for now. If you want to see what the makefile would look like, create a project with the Dev-C++ IDE and have it generate a makefile.

    In order to list the options on the command line, type:
    g++ --help | more
    You will need to pipe to more because the output is longer than one screen. Of course, if your command prompt window is scrollable (eg, as under Win2k), then you won't need to pipe to more.

IMN logo majestic logo threadwatch logo seochat tools logo