Archived

This topic is now archived and is closed to further replies.

vassago74

Trouble compiling in Dev C++

Recommended Posts

vassago74    122
#include <iostream.h> void main () { cout << 10 % 8 << endl; } --Having trouble compiling the program above. I''m new to Dev C++ and any help would be appreciated. After I compile the program a tab for iostream.h pops up and the errors are as follows... 31 C:\Dev-Cpp\include\c++\backward\iostream.h In file included from C:/Dev-Cpp/include/c++/backward/iostream.h 1 C:\Documents and Settings\Nelson Marques\Desktop\test.cpp from C:/Documents and Settings/Nelson Marques/Desktop/test.cpp 2 C:\Dev-Cpp\include\c++\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 header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated. 4 C:\Documents and Settings\Nelson Marques\Desktop\test.cpp `main'' must return --NM

Share this post


Link to post
Share on other sites
JTippetts    12969
Use of the old-style .h headers is deprecated. use #include < iostream > instead.

Also, declare main as:

int main()

or

int main(int argc, char *argv[])

rather than void.

Josh
vertexnormal AT linuxmail DOT org


Check out Golem at:
My cheapass website

[edited by - VertexNormal on September 3, 2003 7:48:02 PM]

Share this post


Link to post
Share on other sites
Vikato    174
Also remember that the new style headers use namespaces, so you either have to put "using namespace std;" to use cout, or you can use the scope resolution operator as in "std::cout << 10 % 8 << endl;"

Share this post


Link to post
Share on other sites
vassago74    122
actually, now i''m getting a few different errors... here they are...

C:\Documents and Settings\Nelson Marques\Desktop\Untitled1.cpp
[Warning] In function:

5 C:\Documents and Settings\Nelson Marques\Desktop\Untitled1.cpp
`cout''

5 C:\Documents and Settings\Nelson Marques\Desktop\Untitled1.cpp
(Each

5 C:\Documents and Settings\Nelson Marques\Desktop\Untitled1.cpp
`endl''

Share this post


Link to post
Share on other sites
vassago74    122
#include <iostream>

int main ()
{
std::cout << 10 % 8 << endl;
}



Ok, the above program still getting these errors..

C:\Documents and Settings\Nelson Marques\Desktop\Untitled1.cpp
[Warning] In function:

5 C:\Documents and Settings\Nelson Marques\Desktop\Untitled1.cpp
`endl''

5 C:\Documents and Settings\Nelson Marques\Desktop\Untitled1.cpp
(Each

Share this post


Link to post
Share on other sites
Vikato    174
I'm sorry, i forgot about endl. If you don't use namespaces, you have to use scope resolution for all objects you use from other libraries, and that includes endl. Try this:

#include <iostream>

int main ()
{
std::cout << 10 % 8 << std::endl;
}



[edited by - Vikato on September 3, 2003 8:05:45 PM]

Share this post


Link to post
Share on other sites
vassago74    122
i agree, thx for the help guys. i was putting the line "using namespaces std" on the same line as #include <iostream> and it wasn''t working, but got it now. thanks again..

Share this post


Link to post
Share on other sites
Soonk    122
hi, kinda new here,
i copied
#include <iostream>

int main ()
{
std::cout << 10 % 8 << std::endl;
}

and when i run the program, the dos window opens but closes right away, so i cant read anything on the screen, why is this? thanks

Share this post


Link to post
Share on other sites
Greatwolf    125
to make it stay on the screen you can use


system("pause");
//need to include the stdlib I believe



Another way is to use

   
getch();
//this one needs to have conio included at the top



And yet another way is to run your executable file with this


cmd /k executable file here
the /k switch here ensures that the dos window remains open after execution is complete. So take your pick





--{You fight like a dairy farmer!}

[edited by - greatwolf on September 5, 2003 2:19:54 AM]

Share this post


Link to post
Share on other sites
FtMonkey    122
The program closes because it reaches the end of main you have to make it "wait" for your input or something like that or it will close use this code instead..


#include <iostream>

int main ()
{
std::cout << 10 % 8 << std::endl;
system("PAUSE"); //wait until you press a key
}

EDIT: heh never mind Greatwolf beat me, I can't type that fast

[edited by - FtMonkey on September 5, 2003 2:24:42 AM]

Share this post


Link to post
Share on other sites
Soonk    122
wow thanks a lot, u guys are great


one more thing, i get
error LNK2001: unresolved external symbol _main
a lot, and ive searched here and im not quite sure i understand how to fix it. can you help?

[edited by - soonk on September 5, 2003 2:29:08 AM]

Share this post


Link to post
Share on other sites