PPP using C++ - Error with first program

Hello,

, I'm trying to learn how to program by reading: "Programming -- Principles and Practice Using C++ (Second Edition)", by Bjarne Stroustrup. Yet I'm stuck at chapter 2, where I'm supposed to create my first program. In my search for a solution I've found many other that has similar problems, although their solutions has allowed me to avoid their errors - I'm now stuck at another error.

Here's the code for the program:
1
2
3
4
5
6
7
8
9
  // This program outputs the message “Hello, World!” to the monitor

#include "../../../std_lib_facilities.h"

int main()             // C++ programs start by executing the function main
{
	cout << "Hello, World!\n";      // output “Hello, World!”
	return 0;
}


And a link to the header I'm supposed to use:
http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h

The instructions that I'm following (word-files):
http://www.stroustrup.com/Programming/include-std_lib_facilities.doc
http://www.stroustrup.com/Programming/Installing-Visual-Studio-express.doc
I've attempted to follow them step-by-step.

And the error I get when I try to build the code:
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
Severity	Code	Description	Project	File	Line	Suppression State
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	7	
Error	C2065	'      ': undeclared identifier	HelloWorld	c:\users\grauth\documents\visual studio 2015\projects\helloworld\helloworld\helloworld.cpp	8	
Error	C2143	syntax error: missing ';' before 'return'	HelloWorld	c:\users\grauth\documents\visual studio 2015\projects\helloworld\helloworld\helloworld.cpp	8	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	7	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	7	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	7	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	7	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	7	
Error	C3873	'0xa0': this character is not allowed as a first character of an identifier	HelloWorld	c:\users\grauth\documents\visual studio 2015\projects\helloworld\helloworld\helloworld.cpp	7	
Error	C3872	'0xa0': this character is not allowed in an identifier	HelloWorld	c:\users\grauth\documents\visual studio 2015\projects\helloworld\helloworld\helloworld.cpp	7	
Error	C3646	'             ': unknown override specifier	HelloWorld	c:\users\grauth\documents\visual studio 2015\projects\helloworld\helloworld\helloworld.cpp	6	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error (active)		unrecognized token	HelloWorld	c:\Users\Grauth\Documents\Visual Studio 2015\Projects\HelloWorld\HelloWorld\HelloWorld.cpp	5	
Error	C3873	'0xa0': this character is not allowed as a first character of an identifier	HelloWorld	c:\users\grauth\documents\visual studio 2015\projects\helloworld\helloworld\helloworld.cpp	5	
Error	C3872	'0xa0': this character is not allowed in an identifier	HelloWorld	c:\users\grauth\documents\visual studio 2015\projects\helloworld\helloworld\helloworld.cpp	5	



My most recent idea is to downgrade to "Visual Studio Express 2010", since the author mentions the version in the instructions. Yet I have almost no knowledge of programming - so I assume there's a better solution, and maybe you know of it? Or a better way to troubleshoot the problem?

Your help is highly appreciated!

/Nils
Last edited on
The code that you posted appears to be fine.

Did you type the code manually into your editor or did you copy paste it from somewhere? Sometimes when copy pasting from the web, a pdf or from a word document you get invisible characters or the wrong characters that look similar. Copy pasting from this site should work without problem so you could try if it works if you copy paste the code of your post into your IDE and then recompile your program.
The path you set to std_lib_facilities.h is not right.

Try moving it up or down some; "../../std_lib_facilities.h", or "../../../../std_lib_facilities.h"
The direction of the slashes could be wrong also, notice the error messages have then the opposite direction.
@Peter87: I now manually wrote the code - and now it works!

Thank you - it really made my day to get this working : D.

@admkrk: thank you for attempting to help : ).


/Cheers,
Nils
admkrk wrote:
The path you set to std_lib_facilities.h is not right.

If that was the case the error messages should have mentioned std_lib_facilities.h somewhere.

admkrk wrote:
The direction of the slashes could be wrong also, notice the error messages have then the opposite direction.

On Windows you can use forward slashes ( / ) or backslashes ( \ ), they both work the same. Backslashes is a bit uglier to type because it's a special character and needs to be escaped by writing a backslash in front of it.
 
"..\\..\\..\\std_lib_facilities.h"
On most other systems only forward slashes can be used as a file path separator.

I would recommend always using forward slashes because it's easier to type and it works everywhere.

NilsAnton wrote:
now it works!

Good! :)
Last edited on
Topic archived. No new replies allowed.