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

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -