在vs2010 (c++, win32)中编写文件
file writing in vs2010 (c++, win32)
我之前问过这个问题,你让我提到错误,所以我现在会提到它们(我不知道如何继续我开始的最后一个线程,我所看到的只是一个"添加评论"按钮和一个"回答你的问题"按钮,所以我不得不纠正问题并再次问,抱歉):
我的问题如下:我正在使用visual studio 2010,我正在编写一个win32应用程序(不是控制台应用程序)。我需要知道如何从这个应用程序写入文件。
我包含了这些头文件:windows.h, stdlib.h, string.h和char.h
我写了一个非常简单的hello world应用程序,它运行得很好。
但是当我尝试包含iostream和fstream时在我的项目中,编译器给了我以下错误:
1>c:program files (x86)microsoft visual studio 10.0vcincludecstdlib(21): error C2039: 'abort' : is not a member of '`global namespace''
1>c:program files (x86)microsoft visual studio 10.0vcincludecstdlib(21): error C2873: 'abort' : symbol cannot be used in a using-declaration
1>c:program files (x86)microsoft visual studio 10.0vcincludecstdlib(24): error C2039: 'exit' : is not a member of '`global namespace''
1>c:program files (x86)microsoft visual studio 10.0vcincludecstdlib(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.0vcincludecstdlib 21 13
IntelliSense: the global scope has no "exit" c:program files (x86)microsoft visual studio 10.0vcincludecstdlib 24 13
当我包含fstream.h时,我得到:
error C1083: Cannot open include file: 'fstream.h': No such file or directory c:usersuserdocumentsvisual studio 2010projectshelloworldhelloworldmain.cpp 5 1 helloworld
IntelliSense: cannot open source file "fstream.h" c:usersuserdocumentsvisual studio 2010projectshelloworldhelloworldmain.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:
#include "stdafx.h"
#include <iostream>
// ... and so on
int main(...) {
}
…这是Microsoft编译器经常犯的错误(参见c++ cout给出未声明的标识符)。
你可能把#include <iostream>
写成了#include "iostream"
也许这有帮助。尝试从
检查错误原因http://msdn.microsoft.com/en-us/library/et4zwx34%28v=vs.80%29.aspx相关文章:
- 尝试使用来自 Win32 WASAPI C++的"捕获流"创建 wav 文件
- 使用 Win32 读取文件时,glShaderSource 访问冲突
- 在 Win32 应用中,如果未选择文件夹并且用户单击"确定",则文件夹选择对话框将关闭
- 如何检查 win32 exe 文件是否已运行?(使用 win32 API 代码)
- Win32 GUI C(++) 应用将标准输出和标准输出重定向到磁盘上的同一文件
- 我无法使用Win32从文件夹中加载图像
- 无法加载.bmp文件win32
- Win32打开一个文件夹
- 为什么我无法使用CreateFile Win32 API打开文件RW,但可以使用STD ::删除将其删除
- 使用 Win32/WINAPI 通过内存映射文件传输数据
- 在 Win32 (C++) 中打开、操作和呈现 SVG 文件
- 用于从资源文件打开和获取数据的 Win32 API
- 如何将任何 *.jpg图像嵌入Win32可执行文件中并在运行时使用它
- Visual Studio 错误:LNK1104:无法打开文件'kernel32.lib' - 仅在 WP8 项目/Win32 版本中
- Win32 查找第一个文件非终止通配符扩展
- 使用文件I/O正确创建和运行win32服务
- 使用Win32/MFC将HTML文件转换为PDF
- C++/Win32 在虚拟内存中创建文件
- Win32从设备上下文到文件和/或BLOB创建位图
- Win32 文件 IO 工作,但打开 et.失败.这是怎么回事