I created a .txt file that I called in.txt. It has the letters: a b c d e.
I put it in the same folder as the c++ code below. I was hoping that I after I compile and run the code, the in.txt file would read: e d c b a.
Unfortunately, it doesn't. Even when I give the ofstream file another name, it does not create another text file. Any idea on what could be causing this?
Code:#include<iostream> #include<fstream> #include <limits> using namespace std; void reverse(char a[],int b); int main(){ int counter=0; char a[100]; ifstream file1; file1.open("in.txt"); while(file1.eof()==false){file1>>a[counter++];} a[counter-1]='/0'; reverse(a,counter-1); file1.close(); ofstream file2; file2.open("in.txt"); for(int i;i< counter-1;i++){ file2<<a[i];} file2.close(); //system("PAUSE"); return 0; } //cin.get(); //std::cout << "Press ENTER to continue..."; //std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ); void reverse(char a[],int b){ char temp; for(int i=0;i=b/2;i++){ temp=a[i]; a[i]=a[b-i-1]; a[b-i-1]=temp;} }




Reply With Quote