为什么我的代码没有显示
问题描述:
我正在尝试使用fstream函数将数据输入到文件并显示输出但是一旦我运行代码,我看到的是按任意键继续
而不是我的输出是代码:
i am trying to use the fstream function to input data to file and show the output but once i run the code all i see is "pres any key to continue"
and not my output here is the code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main(){
ifstream infile;
ofstream outfile;
string firstname, lastname;
double current_salary, percentage_increse;
infile.open("test.txt");
outfile.open("ch3_Ex6Data.txt");
outfile << fixed << showpoint << setprecision(2);
outfile << "Enther employee name: ";
infile >> firstname >> lastname;
outfile << endl;
outfile << "enter employee salary and percentage change";
outfile << endl;
infile >> current_salary >> percentage_increse;
outfile << firstname << lastname << "the current salary is "
<< current_salary << "with a " << percentage_increse
<< "percent increse" << endl;
infile.close();
outfile.close();
return 0;
}
答
它怎么可能有效?您认为infile和outfile可以做什么?
相反,使用cin
和cout
: http://www.cplusplus.com/doc/tutorial/basic_io [ ^ ]。-SA
How could it possibly work? What do you think "infile" and "outfile" could do?
Instead, usecin
andcout
: http://www.cplusplus.com/doc/tutorial/basic_io[^].—SA