STL: Cannot use STLs even though it exists..!!

B

blrmaani

Hi,
I have a simple program as follows: (file name string.cc )

#include <string>
main()
{
string s1 = "test";
}

unix/us/blrmaani/CPP>g++ string.cc
string.cc: In function `int main()':
string.cc:4: `string' undeclared (first use this function)
string.cc:4: (Each undeclared identifier is reported only once for each
function it appears in.)
string.cc:4: parse error before `;' token

unix/us/blrmaani/CPP>ls /usr/local/include/c++/3.2.1/string
/usr/local/include/c++/3.2.1/string


I tried to include the header path

unix/us/blrmaani/CPP>g++ -I /usr/local/include/c++/3.2.1/ string.cc
string.cc: In function `int main()':
string.cc:4: `string' undeclared (first use this function)
string.cc:4: (Each undeclared identifier is reported only once for each
function it appears in.)
string.cc:4: parse error before `;' token

Am I missing something?
thanks
regards

blrmaani
 
K

Karthik

blrmaani said:
Hi,
I have a simple program as follows: (file name string.cc )

#include <string>
main()
ISO Standard suggests you have the return type as int instead of
void, as above.
{
string s1 = "test";
}
You are missing the namespace to resolve 'string'. By default, it is
in std namespace.



#include <string>
#include <cstdlib>
int main()
{
std::string s1 = "test";
return EXIT_SUCCESS;
}
 
O

Old Wolf

Karthik said:
ISO Standard suggests you have the return type as int instead of
void, as above.

In C++, the above is a syntax error, not a return type of void.
In C, it would be a return type of int.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top