I expected the line inside the file, to have the name of the file, but instead the line contains the string that was previously assigned to the string variable used for giving name to the file.
For example, if the name asigned to the file is "Text8.txt" i expected the first line in it was:
Hi World, my name is:Text8.txt
but instead it has the line with text i previously typed.
#include <iostream>
#include <fstream>
#include <string.h>
usingnamespace std;
string outName="E:/FakeOld.txt", newName="E:/FakeNew.txt";
ofstream outFile;
void dtaToSrt();
void outFWho();
int main() {
dtaToSrt (); // will process some data creat some file
system ("pause");
return 0;
}
void dtaToSrt(){
outFWho (); // select a name for outFile ...
// cout <<"Hi World, my name is:"<<outName<<endl;
outFile <<"Hi World, my name is:"<<outName<<endl;
outFile.close();
}
void outFWho() {
cout<<"Give me outFile name:"<<endl;
getline(cin, outName); // Si
cout<<"Please verify...:"<<outName<<endl;
cout<<"Try another one:";
getline(cin, newName);
string outName=newName;
cout<<" Confirmed:"<<outName<<endl;
// outFile.open(outName,ios::in);
outFile.open(outName.c_str());
if(outFile.fail()) {
cout<<"A problem with:"<<outName<<endl;
}
}