【发布时间】:2016-01-14 13:31:42
【问题描述】:
我的程序的一部分包括写入文本文件。我有:
#include<fstream>
#include<iostream>
#include<string>
#include<cstdlib>
#include<ctime>
using namespace std;
//I open the file "highscore.txt" here, read it, and then close it.
ofstream outfile;
outfile.open("highscore.txt", ios::out);
outfile<<score;
outfile.close();
我问了不同的人,它说它看起来不错,但是当我尝试编译它时却收到错误:
“outfile”未在此范围内声明
【问题讨论】:
-
我只看到全局范围。你想做什么?你有 MCVE 吗?
-
你的
main()函数在哪里? -
你的主要功能在哪里?你不能在全局范围内运行代码
-
这不是一个完整的例子,请提供一个更有意义的例子。
-
@skypjack 我怀疑 OP 的问题是这 是他的完整示例 :)