I am trying to write to two files and read from them. I was able to successfully input information to the two files ( words.txt & wordsTwo.txt). When I try to read from the two files, it will come out with symbols and not the text I set for it. Can some one help me solve this problem?
#include<iostream>
#include<fstream>
using namespace std;
int main() {
// creating variables to input to files
ofstream inputFirst;
ofstream inputSecond;
// creating variables to read from files
ifstream readignFirst;
ifstream readingSecond;
inputFirst.open("words.txt");
inputSecond.open("wordsTwo.txt");
readignFirst.open("words.txt");
readingSecond.open("wordsTwo.txt");
if(inputFirst.is_open() && inputSecond.is_open()){
inputFirst<<"red";
inputSecond<<"apple";
}
//close input stream
inputFirst.close();
inputSecond.close();
//storing characters
char characterArrayOne[100];
char characterArrayTwo[100];
//checking to make sure both are files are ready to be read
if (readignFirst.is_open() && readingSecond.is_open() ) {
while (!readignFirst.eof() && !readingSecond.eof() ) {
readignFirst >> characterArrayOne;
readingSecond >> characterArrayTwo;
cout<<" "<<characterArrayOne <<" "<<characterArrayTwo ;
}
}else{
cout<<"please have a input";
}
cout<<" "<<characterArrayOne <<" "<<characterArrayTwo << "test" ;
//close input stream
inputFirst.close();
inputSecond.close();
return 0;
}