簡體   English   中英

vs2010中的文件編寫(C ++,Win32)

[英]file writing in 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也是一樣

為什么會發生這些錯誤?

在C ++中,應該使用<cstdlib>代替<stdlib.h> ,使用<cstring>代替<string.h> (假設您是指C風格的字符串。如果要使用C ++ std :: string,請使用<string> [沒有.h ]。

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

請檢查您的:

#include "stdafx.h"

您的.cpp文件的第一個include。

在這之后寫其他包括:

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

int main(...) {

}

...這是Microsoft編譯器經常發生的錯誤(請參閱C ++ cout提供未聲明的標識符 )。

可能是您編寫了#include "iostream"而不是#include <iostream>

可能會有所幫助..嘗試檢查錯誤原因,從

http://msdn.microsoft.com/zh-CN/library/et4zwx34%28v=vs.80%29.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM