
xcode写c++ Input file opening failed.
#include<iostream>#include<fstream>#include<cstdlib>#include<iomanip>usingnamespacest...
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
void make_neat(ifstream& messy_file, ofstream& neat_file,
int number_after_decimalpoint, int field_width); // must be called by reference;
int main()
{
ifstream fin;
ofstream fout;
fin.open("rawdata.dat");
if(fin.fail())
{
cout<<"Input file opening failed.\n";
system("pause");
exit(1);
}
fout.open("neat.dat");
if(fout.fail())
{
cout<<"Onput file opening failed.\n";
system("pause");
exit(1);
}
make_neat(fin, fout, 5, 12);
fin.close();
fout.close();
cout<<"End of program.\n";
system("pause");
return 0;
}
void make_neat(ifstream& messy_file, ofstream& neat_file,
int number_after_decimalpoint, int field_width) // must be called by reference;
{
neat_file.setf(ios::fixed);
neat_file.setf(ios::showpoint);
neat_file.setf(ios::showpos);
neat_file.precision(number_after_decimalpoint);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.setf(ios::showpos);
cout.precision(number_after_decimalpoint);
double next;
while(messy_file >> next)
{
cout << setw(field_width) << next << endl;
neat_file << setw(field_width) << next << endl;
}
}
然后 rawdata.dat 里是
10.37 -9.89897
2.3131 -8.950 15.0
7.3333333333 92.8765
-1.237568432e2
我把这两个文件放到一起已经,为什么Xcode运行还是报错
Input file opening failed.
sh: pause: command not found
Program ended with exit code: 1 展开
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
void make_neat(ifstream& messy_file, ofstream& neat_file,
int number_after_decimalpoint, int field_width); // must be called by reference;
int main()
{
ifstream fin;
ofstream fout;
fin.open("rawdata.dat");
if(fin.fail())
{
cout<<"Input file opening failed.\n";
system("pause");
exit(1);
}
fout.open("neat.dat");
if(fout.fail())
{
cout<<"Onput file opening failed.\n";
system("pause");
exit(1);
}
make_neat(fin, fout, 5, 12);
fin.close();
fout.close();
cout<<"End of program.\n";
system("pause");
return 0;
}
void make_neat(ifstream& messy_file, ofstream& neat_file,
int number_after_decimalpoint, int field_width) // must be called by reference;
{
neat_file.setf(ios::fixed);
neat_file.setf(ios::showpoint);
neat_file.setf(ios::showpos);
neat_file.precision(number_after_decimalpoint);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.setf(ios::showpos);
cout.precision(number_after_decimalpoint);
double next;
while(messy_file >> next)
{
cout << setw(field_width) << next << endl;
neat_file << setw(field_width) << next << endl;
}
}
然后 rawdata.dat 里是
10.37 -9.89897
2.3131 -8.950 15.0
7.3333333333 92.8765
-1.237568432e2
我把这两个文件放到一起已经,为什么Xcode运行还是报错
Input file opening failed.
sh: pause: command not found
Program ended with exit code: 1 展开
1个回答
展开全部
你具体错误没有打印,而仅仅打印input file opening failed是没有办法知道具体原因的
错误的原因可能有很多种,例如你文件名没有写全路径,因此也许你打开的文件不在你需要的位置
错误的原因可能有很多种,例如你文件名没有写全路径,因此也许你打开的文件不在你需要的位置
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询