trouble with test program. Why wont this run?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;
int main()
{
string HorribleMovie;
string *ptrToString;
HoribleMovie = "L.A. Confidential";
ptrToString = &HorribleMovie;
for (unsigned i = 0; i < HorribleMovie.length(); i++)
{
cout << (*ptrToString)[i] << " ";
}
cout << endl;
return 0;
}

This is stiaght from a book to explain pointers in strings, but it won't compile? It gives an error: stray '\342' in program. Along with that error t gives a massive amount of the same error only the number in it is changed to 200, 234, 342, 200 again, 235, etc. Another error: 'L' was not declared in this scope ANd Error:expexted primary -expression before ':' token.

Ive already tried adding #include <string> but that did not do anything
If anyone can help, that would be great. It's hard to learn C++ when the test prorgrams from books don't work
line 7 contains a typo in the name of the identifier:

HoribleMovie = "L.A. Confidential";

Change to:

HorribleMovie = "L.A. Confidential";

With the above change the code compiles and run correctly on my system.

Topic archived. No new replies allowed.