为什么我的代码没有显示 [英] why is my code not showing

查看:104
本文介绍了为什么我的代码没有显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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, use cin and cout: http://www.cplusplus.com/doc/tutorial/basic_io[^].

—SA


这篇关于为什么我的代码没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆