【问题标题】:file writing in vs2010 (c++, win32)在 vs2010 (c++, win32) 中写入文件
【发布时间】:2013-06-01 10:19:05
【问题描述】:

我之前问过这个问题,你让我提到错误, 所以我现在要提到它们(我不知道如何继续我开始的最后一个线程,我看到的只是一个“添加评论”按钮和一个“回答你的问题”按钮,所以我不得不更正问题和再问一遍,对不起):

我的问题如下: 我正在使用 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++ winapi filestream


    【解决方案1】:

    在 C++ 中,你应该使用 <cstdlib> 而不是 <stdlib.h><cstring> 而不是 <string.h>(假设你的意思是 C 风格的字符串。如果你想要 C++ std::string,请使用 <string> [没有.h]。

    你应该使用<fstream>,而不是<fstream.h>

    【讨论】:

      【解决方案2】:

      请检查您的:

      #include "stdafx.h"

      你的第一个包含.cpp文件。

      在此之后写下其他包含:

      #include "stdafx.h"
      #include <iostream>
      // ... and so on
      
      int main(...) {
      
      }
      

      ...这是 Microsoft 编译器的常见错误(请参阅 C++ cout gives undeclared identifier)。

      【讨论】:

        【解决方案3】:

        可能你写的是#include "iostream"而不是#include &lt;iostream&gt;

        【讨论】:

          【解决方案4】:

          这可能会有所帮助.. 尝试从

          检查您的错误原因

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

          【讨论】:

            猜你喜欢
            • 2023-02-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-09-30
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多