2013-06-01 29 views
0

我剛纔問過這個問題,你告訴我提及錯誤, 所以我現在要提及它們(我不知道如何繼續我開始的最後一個線程,所有我看到是一個「添加評論」按鈕和一個「回答你的問題」按鈕,所以我不得不糾正問題並再次提出,對此表示遺憾):在vs2010中寫文件(C++,win32)

我的問題是以下內容: 我是使用visual studio 2010,我在寫一個win32應用程序(不是控制檯應用程序)。 我需要知道如何從這個應用程序寫入文件。

我包括這些標題:WINDOWS.H,文件stdlib.h,string.h中和TCHAR.H

我寫了一個很簡單的Hello World應用程序,它運行得很好。

但是,當我試圖在我的項目中包括iostream和fstream 編譯器給我以下錯誤。

1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(21): error C2039: 'abort' : is not a member of '`global namespace'' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(21): error C2873: 'abort' : symbol cannot be used in a using-declaration 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(24): error C2039: 'exit' : is not a member of '`global namespace'' 
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib(24): error C2873: 'exit' : symbol cannot be used in a using-declaration 
IntelliSense: the global scope has no "abort" c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib 21 13 
IntelliSense: the global scope has no "exit" c:\program files (x86)\microsoft visual studio 10.0\vc\include\cstdlib 24 13 

當我包括fstream.h,我得到:

error C1083: Cannot open include file: 'fstream.h': No such file or directory c:\users\user\documents\visual studio 2010\projects\helloworld\helloworld\main.cpp 5 1 helloworld 
IntelliSense: cannot open source file "fstream.h" c:\users\user\documents\visual studio 2010\projects\helloworld\helloworld\main.cpp 5 1 helloworld 

爲iostream.h

同樣的事情爲什麼發生這些錯誤?

回答

0

也許你寫#include "iostream"代替#include <iostream>

5

在C檢查錯誤原因++,你應該使用,而不是<cstdlib><stdlib.h><cstring>代替<string.h>(假設你的意思是C風格的字符串,如果你想要C++ std :: string,則使用<string> [不含.h]。

而且您應該使用<fstream>而不是<fstream.h>

+0

+1 - 簡單地說,爲正確的答案。 – SChepurin

1

請檢查您:

#include "stdafx.h"

第一包括你.cpp文件。其他

寫入包括在此之後一個:

#include "stdafx.h" 
#include <iostream> 
// ... and so on 

int main(...) { 

} 

...這是一個相當常見的錯誤與微軟編譯器(見C++ cout gives undeclared identifier)。