March 21st, 2003, 08:28 PM
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:
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?
1: // Listing 2.2 using cout
3: #include <iostream.h>
4: int main()
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;
March 21st, 2003, 08:32 PM
looks fine to me, what is the error u r recieving?
March 21st, 2003, 10:03 PM
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?
March 21st, 2003, 10:20 PM
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.
March 21st, 2003, 11:56 PM
Im working with Dev-C++ compiler.
March 22nd, 2003, 12:49 AM
March 22nd, 2003, 01:06 AM
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.
March 22nd, 2003, 01:02 PM
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.