#include <string>
#include <iostream>
usingnamespace std;
int main()
{
char str[600];
char name[100];
char add[200];
char work[200];
cout >> "Enter name and press ENTER: ";
cin.getline(name, 99);
cout >> "Enter address and press ENTER: ";
cin.getline(addr, 199);
cout >> "Enter workplace and press ENTER: ";
cin.getline(work, 199);
strcpy(str, "\nMy name is ");
strcat(str, name);
strcat(str, "\n, I live at ");
strcat(str, addr);
strcat(str, "\nand I work at ");
strcat(str, work);
cout << str;
return 0;
}
I keep getting "undeclared identifier" errors (89 to be exact) everywhere the string commands are used. I think the problem is in the <string> library but I may be wrong. If it helps I am using Visual C++ 2008. Any help is greatly appreciated.
One problem is that "cout" uses the other-direction carrots.
Instead of: cout >> "Enter name and press ENTER: ";
use: cout << "Enter name and press ENTER: ";
Also note that cin uses the ones you tried:
cin >> var;
will ask the user to input value and store it to var.
Another problem is that in lines 16 and 23, you refer to variable 'addr' when it is declared as 'add[200]'. Change those references to the correct name (add) and it should compile.