problem with including

Aug 6, 2008 at 8:14am
Hi

Im making output with files.

1
2
3
4
5
6
7
8
9
10
11
//...
//lots unrelated code in both sides
#include <fstream>

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
	ofstream output;
	output.open("output.txt");
	output<<"Helo world";
	output.close();
//... 


but when i compile i get errors:
.\main.cpp(31) : error C2065: 'ofstream' : undeclared identifier
.\main.cpp(31) : error C2146: syntax error : missing ';' before identifier 'output'
.\main.cpp(31) : error C2065: 'output' : undeclared identifier
.\main.cpp(32) : error C2228: left of '.open' must have class/struct/union
type is ''unknown-type''
.\main.cpp(34) : error C2228: left of '.close' must have class/struct/union
type is ''unknown-type''

Please help.
Aug 6, 2008 at 8:24am
closed account (z05DSL3A)
Try:
1
2
3
4
5
6
7
8
9
10
11
12
//...
//lots unrelated code in both sides
#include <fstream>

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
	std::ofstream output;  

	output.open("output.txt");
	output<<"Helo world";
	output.close();
//...  
Aug 6, 2008 at 8:57am
sory for such stupid mistake but now i have another problem:
C:\Program Files\Microsoft Visual Studio 8\VC\include\iosfwd(230) : error C2059: syntax error : 'constant'
C:\Program Files\Microsoft Visual Studio 8\VC\include\iosfwd(288) : see reference to class template instantiation 'std::char_traits<_Elem>' being compiled
C:\Program Files\Microsoft Visual Studio 8\VC\include\iosfwd(232) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
C:\Program Files\Microsoft Visual Studio 8\VC\include\iosfwd(355) : error C2059: syntax error : 'constant'
C:\Program Files\Microsoft Visual Studio 8\VC\include\iosfwd(357) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
C:\Program Files\Microsoft Visual Studio 8\VC\include\iosfwd(470) : error C2059: syntax error : 'constant'
C:\Program Files\Microsoft Visual Studio 8\VC\include\iosfwd(472) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body

Aug 6, 2008 at 9:33am
closed account (z05DSL3A)
I can't think of a reason that you would get that error from the code that you have posted.

If you want to rule out the ofstream stuff as the coarse of the error, comment it out and recompile, see if the error goes away.

Try searching your code for 'constant' and see what comes up, It looks like it is related to a function called move.
Aug 6, 2008 at 9:54am
when I comment ofstream stuf program works well but its enough to #include <fstream> and the error comes back.

constant and move are in the iosfwd file
(here are lines 229-235)
1
2
3
4
5
6
7
	_SCL_INSECURE_DEPRECATE
	static _Elem *__CLRCALL_OR_CDECL move(_Elem *_First1,
		const _Elem *_First2, size_t _Count)
		{	// move [_First1, _First1 + _Count) to [_First2, ...)
		// assume there is enough space in the destination buffer
		return _Move_s(_First1, _Count, _First2, _Count);
		}
Topic archived. No new replies allowed.