Click here to Skip to main content
15,908,834 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:


C++
#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;
}
Posted
Updated 1-Feb-15 2:45am
v2
Comments
Andreas Gieriet 1-Feb-15 8:45am    
Fixed question: was wrong language in pre-block.
Andi

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900