I have my Project setup like this.
+TW
TW1
TW2

Before i created the file TW2 i compiled TW1, and TW1 worked fine. When i added TW2, and then compiled it, and started either TW1 or TW2 it said "Project is not compiled". Any idea on how im sposed to use the compiling or if im doing something wrong?

Dont think so, all i did was create the project, and added a new file, put in the code and compiled it as TW1 as a .cpp file. After that i created a new file, put in the code and compiled it as TW2 as a .cpp file also. After that i tried to run the TW2 and it said "Project i not compiled" and then i tried the TW1 and it did the smae thing, even though TW1 worked before i added TW2. So i dont know if there linked or not.
+TW
|-TW1
|-TW2
looks like that in the project manager.

Forgot to add the error when it compiles
3 C:\Dev-Cpp\include\c++\3.3.1\backward\iostream.h:31, from TW1.cpp In file included from C:/Dev-Cpp/include/c++/3.3.1/backward/iostream.h:31, from TW1.cpp
3 C:\Dev-Cpp\TW1.cpp from TW1.cpp
2 C:\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
3 C:\Dev-Cpp\include\c++\3.3.1\backward\iostream.h:31, from TW2.cpp In file included from C:/Dev-Cpp/include/c++/3.3.1/backward/iostream.h:31, from TW2.cpp
3 C:\Dev-Cpp\TW2.cpp from TW2.cpp
2 C:\Dev-Cpp\include\c++\3.3.1\backward\backward_warning.h:32 #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
TW2.cpp C:\Dev-Cpp\TW2.o(.text+0x0) multiple definition of `main'
TW1.cpp C:\Dev-Cpp\TW1.o(.text+0x22) first defined here
C:\Dev-Cpp\Makefile.win [Build Error] [TutorialWork.exe] Error 1

You can only have one main function. And if you bother to listen to people when they tell you to stop using iostream.h, you won't have to look at the warnings complaining about deprecated headers.

So i can only have one int main () per project meaning that i have to do another project for each int main() file? and isn't iostream.h what you need? (Tutorial said to use it)

>So i can only have one int main () per project
Pretty much, yes.

>meaning that i have to do another project for each int main() file?
If each file is an independent program, yes. It's possible to write a .cpp file without main and then link it with the .cpp file that has main:

// header.h
#ifndef SOME_HEADER
#define SOME_HEADER

void function();

#endif
// header.cpp
#include <iostream>
#include "header.h"

void function()
{
  std::cout<<"Hello, world!"<<std::endl;
}
// main.cpp
#include <iostream>
#include "header.h"

int main()
{
  function();
  std::cout<<"Goodbye, world!"<<std::endl;
}

>and isn't iostream.h what you need?
No, it isn't a C++ header.

>Tutorial said to use it
Tutorial was wrong.

So witch library header is most comonly used for C++ compilers? i don't think anything i've done yet uses the iostream.h thing.
Casue baicly the utorial told me to use #include <iostream.h> in all programs i use.

>i don't think anything i've done yet uses the iostream.h thing.
iostream.h is the pre-standard header for standard input and output. Any time you use cin or cout, you need to include iostream. However, with the advent of the C++ standard, iostream.h was removed and replaced with iostream and every name was enclosed in the std namespace.

>Casue baicly the utorial told me to use #include <iostream.h> in all programs i use.
I can understand that, even though you may write programs that don't use iostream. However, your tutorial is old, and thus, wrong. Replace this:

#include <iostream.h>

With this:

#include <iostream>

using namespace std;

And you should be all right for a while. This is only a temporary fix until you're more familiar with the nuances of headers though.

>So witch library header is most comonly used for C++ compilers?
The headers you'll find yourself using most often at first are <iostream>, <string>, <fstream>, <cstdlib>, <cstring>, and <cctype>. All names in the standard C++ library are in the std namespace, so it's a good idea to place the using directive after all includes. For example, if you included all of the above headers, you would do it like so:

#include <cctype>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

So for every program i do, can i just add all of them? i never know when ill add something, and forgot to add the header..

>can i just add all of them?
You can, though it's not a good idea to include headers that you don't use. It confuses people. Then there's the issue of the using directive. Whenever you say

using namespace std;

You are effectively making all names in the std namespace open to the world. If you include a lot of headers that you don't need then you may have naming collisions with your own identifiers. So if you want to include all headers all of the time I would recommend a using declaration for each name you use:

#include <iostream> // Only using cout though!

// Make cout visible, but nothing else
using std::cout;

int main()
{
  cout<<"Hello, world!"<<std::endl;
}

Notice that endl isn't made visible, so you have to qualify it explicitly with std:: every time you use it. This is an encapsulation measure that avoids naming conflicts.

This article has been dead for over six months. Start a new discussion instead.