ok guys, i can not figure out the following problem that i faced just a while ago while trying out some filing in c++.
the code is as follows:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ifstream readFile;
readFile.open("Input.txt");
string sample;
readFile>>sample;
cout<<"Here is a line: "<<sample<<endl;
ofstream outputfile;
outputfile.open("file.txt");
string word;
string word1;
cin>>word1;
outputfile<<word1;
ifstream inputfile;
inputfile.open("file.txt");
inputfile>>word;
cout<<endl<<word;
inputfile.close();
return 0;
}
when i take input from the user and then output that into a file it works, but when i take input from the file immediately from the file i cant do it. it just doesnt work. but when i take input from the file without asking for the input and sending the output to the file, the input from the file works and the value is saved in the variable.
howevere, this problem is happening only when i get input and give output to and from the same file. if get input from a different file it works.
is this a problem in c++ itself or am i just wasting my time trying to figure out stuff which i should not?
__________________