Undefined Symbol 'String'

Using Turbo C++ 4.5, I get the following error when compiling this code:

#include <iostream.h>
#include <string.h>

int main()

{
String Name;
cout<<"Enter Name : ";
cin>> Name;
cout<<"Hello, "<<Name<<"Nice to meet you!";

return(0);

}


Unidentified symbol 'String' in function main().


Can someone please help me identify the problem? I know that's the string library because I looked for it in the compiler's folders.

Much appreciated. Thanks,

Sandman (Tyler)
you should be including <string> not <string.h>, and also <iostream> not <iostream.h>. String name; should be string name;, notice the lower case s.

EDIT - you'll also either need to add using namespace std; beneath your includes, OR instead of string name; put std::string name;
Last edited on
3 problems:

1) You need a newer compiler/IDE. Turbo C++ is ancient. Here are some better options:

http://www.cplusplus.com/articles/chrisname1/


2) You should be including <iostream> and <string>, not <iostream.h> and <string.h>.

3) it's 'string' (lowercase), not 'String'. Also, it's in the std namespace, so it's actually 'std::string'
Including <iostream> and <string> causes more errors. It needs to have ".h" at the end in this case. I'll try downloading a newer compiler and rewrite the code.

I'd appreciate it if someone can edit my code and re-post it so I can see it visually :).

Thanks again.
Including <iostream> and <string> causes more errors. It needs to have ".h" at the end in this case.


That's because of your old compiler.

I'd appreciate it if someone can edit my code and re-post it so I can see it visually :).


This code will work on a modern compiler:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string Name;
    cout<<"Enter Name : ";
    cin>> Name;
    cout<<"Hello, "<<Name<<".  Nice to meet you!";

    return(0);

}
Got wxDev-C++. Did what you said and it compiles and runs. However it closes right away after execution. Here is my code:


#include <iostream>
#include <string>
using namespace std;

int main()

{
string Name;
cout<<"Enter your name : ";
cin>>Name;
cout<<"Hello, "<<Name;

return(0);

}


My IDE uses Delphi to compile.
Last edited on
However it closes right away after execution


There's a sticky on the forum about this very issue:

http://www.cplusplus.com/forum/beginner/1988/

Many suggestions for fixing the problem lie within.
Topic archived. No new replies allowed.