【问题标题】:"Cannot open include file: 'ofstream'" error in Visual Studio 2010 Express Edition?Visual Studio 2010 速成版中的“无法打开包含文件:'ofstream'”错误?
【发布时间】:2012-04-18 23:51:51
【问题描述】:

我是 C++ 的新手,当我尝试编译我的项目时,Visual Studio 2010 Express 遇到了一个致命错误,提示“无法打开包含文件:'ofstream':没有这样的文件或目录”我的实现文件(我遇到错误的地方)如下:

#include "Character.h"
#include <iostream>
#include <ofstream>

using namespace std;

ofstream characterSave;

// Sets the character's name to what the user inputted
void Character::setName(string name)
{
    // Set characterName to equal what user inputted
    characterName = name;
}

// Output the character's name when called
string Character::getName()
{
    // Return characterName
    return characterName;
}

// Save the user's data to save.dat
void Character::saveToFile()
{
    // Creates new save file
    characterSave.open("character.dat");

    // Writes character's name to first line of save file
    characterSave << characterName << endl;

    // Closes save file
    characterSave.close();
}

我在网上四处搜索,但找不到其他有此问题的人。会不会是我本地的 Visual Studio Express 副本?任何帮助将不胜感激。

【问题讨论】:

  • Google for ofstream,第一个 result 显示您需要标题 &lt;fstream&gt;

标签: c++ visual-studio visual-studio-2010 ofstream


【解决方案1】:

你需要

#include <fstream>

这就是声明ofstream 的地方。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-30
    • 2012-06-23
    • 1970-01-01
    • 2016-11-29
    • 2016-07-02
    • 2012-05-02
    • 1970-01-01
    相关资源
    最近更新 更多