【发布时间】:2016-08-05 12:45:45
【问题描述】:
所以我是编程新手,我正在学习一个教程,我开始使用 fstream,但我不知道我的编译器是否表现得很奇怪,或者我缺少文件或其他东西,但 .open 函数确实如此似乎不起作用,fstream 的行为很奇怪。 (就像你不能使用(ostreamobject)(“test.txt”)一样;我是编程新手,所以请不要使用技术术语。
我搜索了一下,但没有找到任何东西。
我不知道我的代码或编译器出了什么问题,但 outputFile.open 的存在并不奇怪。我正在使用 Visual Studio 2015。这是我编写的少量代码,但仍然出现错误。代码如下:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ostream oFile;
istream iFile;
oFile.open("test.txt");
return 0;
}
这是错误代码:
1>d:\dokument\visual studio 2015\projects\fstream\fstream\fstream.cpp(13): 错误 C2512: 'std::basic_ostream>': 没有合适的默认构造函数可用 1> d:\programmering\vc\include\iosfwd(679): 注意:见'std::basic_ostream>'的声明 1>d:\dokument\visual studio 2015\projects\fstream\fstream\fstream.cpp(14): 错误 C2512: 'std::basic_istream>': 没有合适的默认构造函数可用 1> d:\programmering\vc\include\iosfwd(678): 注意:见'std::basic_istream>'的声明 1>d:\dokument\visual studio 2015\projects\fstream\fstream\fstream.cpp(16): error C2039: 'open': is not a member of 'std::basic_ostream>' 1> d:\programmering\vc\include\iosfwd(679): 注意:见'std::basic_ostream>'的声明 ========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========
【问题讨论】: