This is my first time working with outputting data to a file, so I've got some rough code that I need some pointers on.
else if (decision == "S" || decision == "s"){
cout << "File name? " <<"("<<filename<<")"<< endl;
cin >> newfile;
if (newfile == '/0'){
outdata.open("filename");
for (k =0; k < rows; k++){
for (m =0; m < cols; m++)
outdata<< (image[k][m]);
outdata<< "\n";
outdata.close();
}
}
return 0;
// else {
// outdata.open("newfile");
// for (k =0; k < rows; k++){
// for (m =0; m < cols; m++)
// outdata<< (image[k][m]);
// outdata<< "\n";
// outdata.close();
// }
// }
// return 0;
}
If the person doesn't enter anything then it overwrites the file that was opened, and if the user enters something then it just pours the image into that filename. I'm not sure how to use null string, and also the outdata.open requires quotation marks around whatever is inside the parenthesis so I can't use the two strings filename and newfile. And I turned my else statement into a comment at the moment because the compiler doesn't like it so I'm trying to figure out what's wrong with that now.