int main() { const int amount = 3; //variable r b g string sentence, filename, f
ID: 3934100 • Letter: I
Question
int main()
{
const int amount = 3; //variable r b g
string sentence, filename, filename2; //variable to hold comments and filename
ifstream inputFile, inputFile2; //open input and output file
ofstream outputFile;
outputFile.open("Alec001.ppm"); //file to open in irfan
cout << "enter a file1 " << endl; // user prompt
cin >> filename;
inputFile.open(filename.c_str());
cout << "enter a file2 " << endl;
cin >> filename2;
inputFile.open(filename.c_str());
inputFile >> newpixel.mgicnum;//read in header information
inputFile.open(filename2.c_str());
inputFile >> newpixel2.mgicnum;
cout << newpixel.mgicnum ;
cout << newpixel2.mgicnum;
I need to read in two files a and b, compare contents a[i] to b[i] - so I m checkvariables and nothing is being fillled = what am I doing wrong
newpixel.mgicnum and newpixel2.mgicnum - no output or 0
Explanation / Answer
int main()
{
const int amount = 3; //variable r b g
string sentence, filename, filename2; //variable to hold comments and filename
// declare header variables, variavle names corrected
string newpixel_mgicnum,newpixel2_mgicnum;
ifstream inputFile, inputFile2; //open input and output file
ofstream outputFile;
outputFile.open("Alec001.ppm"); //file to open in irfan
cout << "enter a file1 " << endl; // user prompt
cin >> filename;
inputFile.open(filename.c_str());
cout << "enter a file2 " << endl;
cin >> filename2;
inputFile.open(filename.c_str());
inputFile >> newpixel_mgicnum;//read in header information
inputFile.open(filename2.c_str());
inputFile >> newpixel2_mgicnum;
cout << newpixel_mgicnum ;
cout << newpixel2_mgicnum;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.