Problem with example of a book

Hello,
thanks in advance for any help.
I am reading Bjarne Stroustrup`s Programming: Principles and Practice Using C++.
System OS:Windows 7 RC 7100; Compiler - Visual Studio 2008 Team System

I am on the first example which is :
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;
}

I `ve installed the FLTK according to the apendix and I downloaded and put the std_lib_facilities.h into the include folder but the result in the compilation is this :
------ Build started: Project: test hello world, Configuration: Debug Win32 ------
Compiling...
test hello world.cpp
y:\visualstudio\vc\include\math.h(62) : error C3861: 'floor': identifier not found
y:\visualstudio\vc\include\cmath(21) : error C2039: 'acosf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(21) : error C2873: 'acosf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(21) : error C2039: 'asinf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(21) : error C2873: 'asinf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(22) : error C2039: 'atanf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(22) : error C2873: 'atanf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(22) : error C2039: 'atan2f' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(22) : error C2873: 'atan2f' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(22) : error C2039: 'ceilf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(22) : error C2873: 'ceilf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(23) : error C2039: 'cosf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(23) : error C2873: 'cosf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(23) : error C2039: 'coshf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(23) : error C2873: 'coshf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(23) : error C2039: 'expf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(23) : error C2873: 'expf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(24) : error C2039: 'fabsf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(24) : error C2873: 'fabsf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(24) : error C2039: 'floorf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(24) : error C2873: 'floorf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(24) : error C2039: 'fmodf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(24) : error C2873: 'fmodf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(25) : error C2039: 'frexpf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(25) : error C2873: 'frexpf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(25) : error C2039: 'ldexpf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(25) : error C2873: 'ldexpf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(25) : error C2039: 'logf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(25) : error C2873: 'logf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(26) : error C2039: 'log10f' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(26) : error C2873: 'log10f' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(26) : error C2039: 'modff' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(26) : error C2873: 'modff' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(26) : error C2039: 'powf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(26) : error C2873: 'powf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(27) : error C2039: 'sinf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(27) : error C2873: 'sinf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(27) : error C2039: 'sinhf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(27) : error C2873: 'sinhf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(27) : error C2039: 'sqrtf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(27) : error C2873: 'sqrtf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(28) : error C2039: 'tanf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(28) : error C2873: 'tanf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(28) : error C2039: 'tanhf' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(28) : error C2873: 'tanhf' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(30) : error C2039: 'acosl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(30) : error C2873: 'acosl' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(30) : error C2039: 'asinl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(30) : error C2873: 'asinl' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(31) : error C2039: 'atanl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(31) : error C2873: 'atanl' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(31) : error C2039: 'atan2l' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(31) : error C2873: 'atan2l' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(31) : error C2039: 'ceill' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(31) : error C2873: 'ceill' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(32) : error C2039: 'cosl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(32) : error C2873: 'cosl' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(32) : error C2039: 'coshl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(32) : error C2873: 'coshl' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(32) : error C2039: 'expl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(32) : error C2873: 'expl' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(33) : error C2039: 'fabsl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(33) : error C2873: 'fabsl' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(33) : error C2039: 'floorl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(33) : error C2873: 'floorl' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(33) : error C2039: 'fmodl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(33) : error C2873: 'fmodl' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(34) : error C2039: 'frexpl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(34) : error C2873: 'frexpl' : symbol cannot be used in a using-declaration

y:\visualstudio\vc\include\cmath(34) : error C2039: 'logl' : is not a member of '`global namespace''
y:\visualstudio\vc\include\cmath(34) : error C2873: 'logl' : symbol cannot be used in a using-declaration
y:\visualstudio\vc\include\cmath(35) : error C2039: 'log10l' : is not a member of '`global namespace''

!!! I SKIPPED MOST OF THE MISTAKES ( THEY ARE STILL CONNECTED TO CMATH) DUE TO MESSAGE LIMITATION!!!
Sorry for the capslocks!

y:\visualstudio\vc\include\cmath(43) : fatal error C1003: error count exceeds 100; stopping compilation
Build log was saved at "file://c:\Users\Strashniq\Documents\Visual Studio 2008\Projects\test hello world\test hello world\Debug\BuildLog.htm"
test hello world - 102 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I got no idea what to do...
Thanks Again!
Last edited on
I have never seen "stb_lib_facilities.h" before...try just including cmath and stuff yourself and see if you get the same errors.
I will add the stb_lib_facilities.h here :
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
	simple "Programming: Principles and Practice using C++" course header to
	be used for the first few weeks.
	It provides the most common standard headers (in the global namespace)
	and minimal exception/error support.

	Students: please don't try to understand the details of headers just yet.
	All will be explained. This header is primarily used so that you don't have
	to understand every concept all at once.
*/

#ifndef H112
#define H112 200608L

#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
#include<stdexcept>
using namespace std;


template<class T> string to_string(const T& t)
{
	ostringstream os;
	os << t;
	return os.str();
}

struct Range_error : out_of_range {	// enhanced vector range error reporting
	int index;
	Range_error(int i) :out_of_range("Range error: "+to_string(i)), index(i) { }
};


// trivially range-checked vector (no iterator checking):
template< class T> struct Vector : public std::vector<T> {
	typedef typename std::vector<T>::size_type size_type;

	Vector() { }
	explicit Vector(size_type n) :std::vector<T>(n) {}
	Vector(size_type n, const T& v) :std::vector<T>(n,v) {}

	T& operator[](unsigned int i) // rather than return at(i);
	{
		if (i<0||this->size()<=i) throw Range_error(i);
		return std::vector<T>::operator[](i);
	}
	const T& operator[](unsigned int i) const
	{
		if (i<0||this->size()<=i) throw Range_error(i);
		return std::vector<T>::operator[](i);
	}
};

// disgusting macro hack to get a range checked vector:
#define vector Vector

// trivially range-checked string (no iterator checking):
struct String : std::string {
	
	String() { }
	String(const char* p) :std::string(p) {}
	String(const string& s) :std::string(s) {}
	String(int sz, char val) :std::string(sz,val) {}
	template<class Iter> String(Iter p1, Iter p2) : std::string(p1,p2) { }

	char& operator[](unsigned int i) // rather than return at(i);
	{
		if (i<0||size()<=i) throw Range_error(i);
		return std::string::operator[](i);
	}

	const char& operator[](unsigned int i) const
	{
		if (i<0||size()<=i) throw Range_error(i);
		return std::string::operator[](i);
	}
};



struct Exit : runtime_error {
	Exit(): runtime_error("Exit") {}
};

// error() simply disguises throws:
inline void error(const string& s)
{
	throw runtime_error(s);
}

inline void error(const string& s, const string& s2)
{
	error(s+s2);
}

inline void error(const string& s, int i)
{
	ostringstream os;
	os << s <<": " << i;
	error(os.str());
}

#if _MSC_VER<1500
	// disgusting macro hack to get a range checked string:
	#define string String
	// MS C++ 9.0 have a built-in assert for string range check
	// and uses "std::string" in several places so that macro substitution fails
#endif

template<class T> char* as_bytes(T& i)	// needed for binary I/O
{
	void* addr = &i;	// get the address of the first byte
						// of memory used to store the object
	return static_cast<char*>(addr); // treat that memory as bytes
}


inline void keep_window_open()
{
	cin.clear();
	cout << "Please enter a character to exit\n";
	char ch;
	cin >> ch;
	return;
}

inline void keep_window_open(string s)
{
	if (s=="") return;
	cin.clear();
	cin.ignore(120,'\n');
	for (;;) {
		cout << "Please enter " << s << " to exit\n";
		string ss;
		while (cin >> ss && ss!=s)
			cout << "Please enter " << s << " to exit\n";
		return;
	}
}

// make std::min() and std::max() accessible:
#undef min
#undef max

#include<iomanip>
inline ios_base& general(ios_base& b)	// to augment fixed and scientific
{
	b.setf(ios_base::fmtflags(0),ios_base::floatfield);
	return b;
}

// run-time checked narrowing cast (type conversion):
template<class R, class A> R narrow_cast(const A& a)
{
	R r = a;
	if (A(r)!=a) error(string("info loss"));
	return r;
}


inline int randint(int max) { return rand()%max; }

inline int randint(int min, int max) { return randint(max-min)+min; }

#endif 


The problem is that I am just starting to study C++ and I am not sure what you are talking about.
If someone has such problem or has heard something about it I would be very grateful /and I will be able to start studying C++/.

I got no idea of all this-that is in the header, that`s why I don`t try to change it any way.
Last edited on
I've never seen code like this before for someone 'just starting to study C++" :\
Um, don't use that header...it seems like mostly BS..."ranged checked string"??? The ****, that is was .at() is FOR!! [] is SPECIFICALLY made to NOT do a range check.
I'm showing my concern about #including things absolutely unnecessary to your program - you used nothing except std::cout from <iostream>.
i think you use namespace std;
As far as I know this header was created so I will not need to include any headers of myself/will be included by themselvs/ so i will not bother with them until i learn whats going on.The problem is that in the begining of the book he is using only this header and nothing else.
And because I don`t know what to put instead - I am f*cked up!
That header was made specifically I think for use with the book examples.
That`s right , and because its Bjarne Stroustrup and he says he checked his code on most OS - so i believe I can run it in Windows 7./At least I hope/
Bjarne's header does not seem very helpful... try this instead

1
2
3
4
5
6
7
#include <iostream>
using namespace std;
int main( )
{
           cout << "Hello World!\n";
           return 0;
}
Topic archived. No new replies allowed.