[SOLVED] String library question

As a beginner, self-taught, programming hopeful, I came across this code in the book that I am learning from:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <string>
#include <iostream>

using namespace 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.
Last edited on
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.

Good luck.
Last edited on
Thank you!!

It did compile for me.
I can't believe I had the cout carots turned the wrong way. And here I thought the #include library was wrong.

Thanks again.
Topic archived. No new replies allowed.