About write file and read file in C++

When I wrote codes below into my visual C++, and begin to run, there is no error and the console have nothing.Does the line "ofstream sals("salaries.txt");" means you're opening a file already existed called "salaries.txt"?But firts I set up a WIN32 console applicaion-> sorce file I already give my file a new?Am I trying to open another file(salaries.txt) in my own sorce code?


I'm supposed to get the result
Name Salaies
--------------- -------
Hank Williams 28422.82
Buddy Holly 58422.82
Nicolas Tse 98422.82



#include<iostream>
#include<iomanip>
#include<fstream>

using namespace std;

int main()
{
ofstream sals("salaries.txt");
sals<<setprecision(2);
sals<<fixed;
sals<<left;

sals<<setw(20)<<"Name"<< setw(10)<<"salary";
sals<<endl;

sals<<"------------------- ";
sals<<"----------"<<endl;

sals<<setw(20)<<"Hank Williams";
sals<<setw(10)<<28422.82<<endl;
sals<<setw(20)<<"Buddy Holly";
sals<<setw(10)<<58422.82<<endl;
sals<<setw(20)<<"Nicolas Tse";
sals<<setw(10)<<98422.82<<endl;

sals.close();
return 0;
}
Yes. "salaries.txt" should be an already existing file in the same directory/folder as your program.
Topic archived. No new replies allowed.