2012-04-05 157 views
1

我对C++相当陌生,当我试图编译我的项目时,Visual Studio 2010 Express遇到了一个致命错误,说“无法打开包含文件:'ofstream':没有这样的文件或目录”源代码之一我的执行文件(在那里我遇到的错误)如下:“在Visual Studio 2010 Express Edition中无法打开包含文件:'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副本吗?任何帮助将非常感激。

+0

Google for ['ofstream'](https://www.google.co.uk/search?q=ofstream),首先[结果](http://www.cplusplus.com/reference/iostream/ofstream) /)显示你需要标题'' – 2012-04-05 09:33:37

回答

3

你需要

#include <fstream> 

这就是ofstream声明。

+0

谢谢!最后让它工作。 – 2012-04-05 22:53:23

相关问题