string - Can't get outfile to read data from infile(c++) -


data in input file:

wilson jack 87236.45 11

my code:

#include <iostream> #include <fstream> #include <iomanip> #include <string> using namespace std;  int main() {      ofstream out;      ifstream in;  string lastname, firstname; double salary; int increase;  in.open("lab5_ex_3_input.txt"); out.open("lab5_ex_3_output.txt");    in >> lastname >> firstname >> salary >> increase; out << "lastname: "<< lastname << "firstname " << firstname << "salry :" << salary <<"increase: "<< increase <<endl;     in.close(); out.close();  return 0; } 

so, when check output file getting:

lastname: firstname salry :-9.25596e+061increase: -858993460

what doing incorrectly?

try this:

if (!(cin >> value >> value2 >> value3)) {     cout << "input failed" << endl;     return -1; } 

my guess input fails. check if file opened correctly @ all, code missing.

btw: there's no need explicitly close streams, closed automatically when go out of scope , destructor called.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -