Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 20, 2002 Compiler Help | ||||
---|---|---|---|---|
| ||||
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 |
April 20, 2002 Re: Compiler Help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel Leach | 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/ |
April 20, 2002 Re: Compiler Help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joel Leach | 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 > > |
February 26, 2004 Re: Compiler Help | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steve Topilnycky | 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/ > > > |
Copyright © 1999-2021 by the D Language Foundation