www.digitalmars.com         C & C++   DMDScript  

c++.command-line - Compiler Help

reply "Joel Leach" <spininc earthlink.net> writes:
Hi,
I tried to compile the program shown below, but got the following error
message:

String name:       //define name
              ^

1.1.cpp(10)    :    Error: undefined identifier 'string'
--- errorlevel 1

Code:

// ask for a person's name, and greet the person
#include <iostream.h>
#include <string.h>

int main(void)
{
// ask for the person's name
cout << "Please enter your first name: ";

// read the name
string name;       // define name
cin >> name;    // read into name

// write a greating
cout << "Hello, " << name << "!" << endl;
return 0;
}

If anyone knows why I'm getting this error, it would be greatly appreciated!

Thanks in advance,
Nicky
Apr 19 2002
next sibling parent reply Steve Topilnycky <no.spam.steve topcatcomputing.com> writes:
In the c++.command-line newsgroup Joel Leach wrote: 

 

Here's your problem.

 string name;       // define name
You have to define it as char, as there is no string definition. You can do it two ways: Method 1: //Define name with a Fixed size: char name[25]; Method 2: // Define a pointer to Name: char *name; Just replace string name; with one of the methods above. They both will work. -- Regards, Steve Topilnycky Top Cat Computing Web: http://www.topcatcomputing.com:8080/
Apr 19 2002
parent "John Hayes" <alexhayes ilstu.edu> writes:
Thanks Steve!  I had the exact same problem and using the pointer worked for
me...thanks again!

John

"Steve Topilnycky" <no.spam.steve topcatcomputing.com> wrote in message
news:MPG.172a87b960b0753d989682 news.digitalmars.com...
 In the c++.command-line newsgroup Joel Leach wrote:



 Here's your problem.

 string name;       // define name
You have to define it as char, as there is no string definition. You can do it two ways: Method 1: //Define name with a Fixed size: char name[25]; Method 2: // Define a pointer to Name: char *name; Just replace string name; with one of the methods above. They both will work. -- Regards, Steve Topilnycky Top Cat Computing Web: http://www.topcatcomputing.com:8080/
Feb 26 2004
prev sibling parent "Walter" <walter digitalmars.com> writes:
The trouble is that "string" is not defined anywhere, see where I marked it
in the code. -Walter

"Joel Leach" <spininc earthlink.net> wrote in message
news:a9qbs1$22oi$1 digitaldaemon.com...
 Hi,
 I tried to compile the program shown below, but got the following error
 message:

 String name:       //define name
               ^

 1.1.cpp(10)    :    Error: undefined identifier 'string'
 --- errorlevel 1

 Code:

 // ask for a person's name, and greet the person
 #include <iostream.h>
 #include <string.h>

 int main(void)
 {
 // ask for the person's name
 cout << "Please enter your first name: ";

 // read the name
 string name;       // define name
^^^^^ this is undefined. -Walter
 cin >> name;    // read into name

 // write a greating
 cout << "Hello, " << name << "!" << endl;
 return 0;
 }

 If anyone knows why I'm getting this error, it would be greatly
appreciated!
 Thanks in advance,
 Nicky
Apr 19 2002