Advertisement

C++ Workshop - Getting Started with C++ (Ch. 1 & 2)

Started by June 01, 2006 11:40 AM
182 comments, last by Dbproguy 16 years, 9 months ago
first of all im useing dev c++

and i get a problem or bug see if im doing this right


#include <iostream.h>

int main();
{
count <<"hello world!\n";
return 0;
}
it says source file not there
i found out the problem

but now i have a different problem i press compile and run and the camand promt screen flashs it does not show me any thing
Advertisement
Quote:
Original post by londonman
i found out the problem

but now i have a different problem i press compile and run and the camand promt screen flashs it does not show me any thing


Well, the program you showed has at least 4 errors from what I see. It should be:

#include <iostream>int main(){    std::cout << "Hello World\n";    return 0;}


The problem with the command prompt dissapearing is common. Since it is a console application, it is meant to be run from the console. If you do this, it will run perfectly. However, since you are executing it from the IDE, the window dissapears as soon as the program finishes. In Visual Studio, you can choose to "Start without debugging" which will ensure the window stays up at completion. I have no experince with Dev-C++ if their is something similar.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
it had 2 errors and i found them out already

but i have a diferent problem how do i run the program
useing dev
i dount get any of this part
The steps to create an executable file are
1. Create a source code file, with a .CPP extension.

2. Compile the source code into a file with the .OBJ extension.

3. Link your OBJ file with any needed libraries to produce an executable program.
i get creat a source file
plz help
Quote:
Original post by londonman
it had 2 errors and i found them out already

but i have a diferent problem how do i run the program
useing dev
i dount get any of this part
The steps to create an executable file are
1. Create a source code file, with a .CPP extension.

2. Compile the source code into a file with the .OBJ extension.

3. Link your OBJ file with any needed libraries to produce an executable program.
i get creat a source file
plz help


Did you follow the advice in this post? Again, I haven't used Dev-C++, but those instructions seem complete.

Edit: My link does not appear to work, just look at the second post in this thread.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
#include <iostream.h>
int main()
{
int x = 5;
int y = 7;
cout "\n";
cout << x + y<< ""<< x * y;
cout "\n";
return 0;
}
it says ther two errors in this i cant see them i been loking at it for 30 mins
Advertisement
Quote:
Original post by londonman
#include <iostream.h>
int main()
{
int x = 5;
int y = 7;
cout "\n";
cout << x + y<< ""<< x * y;
cout "\n";
return 0;
}
it says ther two errors in this i cant see them i been loking at it for 30 mins


I see several problems. First of all, you are using the old deprecated header "iostream.h". Cahnge it to "iostream" (no ".h"). Then, the errors you are getting are due to the fact that you are not using "<<" opertaor when you try to send the new lines. Finally, you are not correctly specifying that cout resides in the std namespace. You must either prefix all of your cout calls with "std::"
or specify to include the namespace (using std::cout).

The correct code would be:

#include <iostream>int main(){    int x = 5;    int y = 7;    std::cout << "\n";    std::cout << x + y << " " << x * y;     std::cout << "\n";    return 0;}


I recommend reading through this thread, as many of the errors are discussed and more in depth explainations are given.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
i wonder y it did not have that program in the book i tryed coping every thing in the book and i got those errors but thx for helping me it worke
it would be cool too see it to rather then it flashing on the screen and disaperring if any body have a solutin tell us

im useing dev
Quote:
Original post by londonman
i wonder y it did not have that program in the book i tryed coping every thing in the book and i got those errors but thx for helping me it worke
it would be cool too see it to rather then it flashing on the screen and disaperring if any body have a solutin tell us

im useing dev


The supported develepoment environment is Visual Studio Express. I told you how to set it up with that. This is a very common problem and should have multiple answers in this thread and found on google.

Of course, You can easily run the program from the command line and it will run correctly and not disappear.

Edit: According to this page, it should work fine by hitting "Run".

Quote:

7. To compile (but not also link) the source program, use Compile option of the Execute menu (or click the Compile tool, pictured as ). The "Building-resource-file/Linking-files/Compilation-complete" window appears (the title changes with the phase of compilation). If there are errors, then they are listed in the bottom pane of the window. Clicking the Continue button (i.e., ) will hide the "Compilation‑complete" window. Double-clicking on a specific error message will cause the highlighting of the offending statement of the source program. The offending statement can then be modified.



8. Assuming there are no compiler or linking errors, use the Run option of the Execute menu (or click on the Run Project tool ). A Command-Prompt window will appear and begin executing the compiled program. The last item displayed in this window will be "Press any key to continue . . ."; pressing a key like ENTER or the space bar, causes the execution window to disappear and Dev-C++ environment to reappear.


Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
When working on a big project, how will the final product be structured ? Will it be all in a single .ccp file like, a 100 meg text file ? Or can you create multiple programs, compile them in .obj and then link them all together ?

Thanks.

This topic is closed to new replies.

Advertisement