THE ZEPINT NETWORK

programmer assist

C++ C++ XML Feeds

C++ Questions C++ Solutions C++ Articles

C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for creating large-scale applications. C++ is a superset of the C language. A related programming language, Java, is based on C++ but optimized for the distribution of program objects in a network such as the Internet. Java is somewhat simpler and easier to learn than C++ and has characteristics that give it other advantages over C++. However, both languages require a considerable amount of study.

Strange error with C++ code

DiggBlinkRedditDeliciousTechnorati

question by Steven | Moderate

.

include <iostream> //**required for cout and cerr



using namespace std;



int main() {

cout << "Hello class";

return 0;

}

When I try to build it I get the following

1>------ Build started: Project: quicksort, Configuration: Debug Win32 ------
1>Compiling...
1>quicksort.cpp
1>c:\documents and settings\jason byrd\my documents\visual studio 2005\projects\quicksort\quicksort\quicksort.cpp(1) : error C2143: syntax error : missing ';' before '<'
1>c:\documents and settings\jason byrd\my documents\visual studio 2005\projects\quicksort\quicksort\quicksort.cpp(1) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\jason byrd\my documents\visual studio 2005\projects\quicksort\quicksort\quicksort.cpp(11) : error C2065: 'cout' : undeclared identifier
1>Build log was saved at "file://c:\Documents and Settings\Jason Byrd\My Documents\Visual Studio 2005\Projects\quicksort\quicksort\Debug\BuildLog.htm"
1>quicksort - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Can anyone tell me what is going wrong?

Post reply Subscriptions

Re: some c++ problem

reply by Steven

I am trying to code this in Microsoft Visual Studio.

Post reply Subscriptions

Re: some c++ problem

reply by Abhishek Chatterjee

Firstly, you need to #include<iostream.h> not just iostream.
Visual C++ doesn't assume header extension.
Also you are forgetting '# (read Hash)'before the include statement.

Hope now it should run :-)

Post reply Subscriptions

Re: Strange error with C++ code

reply by Support@PA

[comment removed]

Post reply Subscriptions

Re: Strange error with C++ code

reply by Srirangan

Steven, please change:
include <iostream>
to:
#include <iostream>

>> Firstly, you need to #include<iostream.h> not just iostream.
Hmm, he did mention the line: using namespace std; so <iostream> is correct.

Post reply Subscriptions

Re: Strange error with C++ code

reply by Abhishek Chatterjee

Yeah fine, still, I did mention the # also :-)

Post reply Subscriptions

Re: Strange error with C++ code

reply by mastercomputers

The problem is missing the # for the preprocessor include, e.g. #include <iostream>

There's a difference between using <iostream.h> and <iostream> and the preferred method is without the extension. VC++ should be able to understand <iostream> so I don't know why it was suggested that it should include the older/backwards compatible means of the header file.

Those three errors, especially the last one should have pinpointed the problem for you, 'cout': undeclared identifier, the only reason it'd be undeclared is if you did not include the relevant header files, you assumed you had but because of incorrect syntax you got the first two errors which did not understand how to compile include <iostream>.

A lot of programmers debate over the use of using namespace std, For me, I don't mind if people use it or not but some alternatives is just using what you need, e.g. using std::cout; using std::endl; instead of using namespace std;

It's also a good idea to do cout << "Hello class" << endl; because endl not only gives a new line but flushes the output buffer too, although if you did not want a newline, then you can ignore that.

Post reply Subscriptions

Got a C++ Question?

Just Sign Up and ask the top C++ experts!

Search via Google

User Login

Email Address

Password

C++ Experts

Rank Expert Points
#1 Support@PA 500
This a list of the Top C++ experts, how many points do you have?

Leading Experts

Rank Expert Points
#1 frankzzsword 4600
#2 Bejaan 2900
#3 csfreak 1100
#4 Anurag 700
#5 keyvez 700
#6 nnarasimha 600
#7 Nakata 600
#8 martinig 600
#9 mastercomputers 400
#10 Huntress 150
#11 Adkron 150
#12 Yogesh 100
#13 lexxwern 100
#14 Mustan Khan 100
#15 poizn 100
This is a list of overall best performing experts, how many points do you have?