【发布时间】:2014-11-25 06:26:55
【问题描述】:
我正在编写一个简单的 c++ 脚本,并希望将打开文件的整个过程放在一个函数中。但是,当我尝试时,我的主要功能出现错误。谁能帮我?这是我的代码:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
string openFile(string fileName);
int main(void)
{
string fileName;
cout << "Please input the file name (including the extension) for this code to read from." << endl;
cin >> fileName;
openFile(fileName);
fout << "File has been opened" << endl;
return 0;
}
string openFile(string fileName)
{
ifstream fin(fileName);
if (fin.good())
{
ofstream fout("Output");
cout << fixed << setprecision(1);
fout << fixed << setprecision(1);
//Set the output to console and file to be to two decimal places and
//not in scientific notation
}
else
{
exit(0);
}
}
【问题讨论】:
标签: c++ file function input output