I am working on a program, it asks user for a file name and opens that file with that name, do some calculations and create a new file with the filename.output (.output is the extension) and save the contents into it. I have been working on it for a while. But while I did able to figured out the part where it ask the user for the file name and open that new..., I can't figure out how to actually add the extension. (I am new to programming...)
Because the file name will not be a know size, I am not sure where could I start adding the .output to the file name. I understand char fileName is just an array of char, but I don't know where to start adding...
ifstream infile ; char fileName ; cout << "Enter the file name: " << endl ; cin >> fileName ; infile.open( fileName ) ; // ofstream of(FileName.output, ios::out)
for exampe, the user entered "word.txt", I would like the output to be word.txt.output. But I am not know how long the name would be in advance, all I know is it will be 1-15 characters long. The last line doesn't work, because the file name isn't like the string i used to work with, I can't just do fileName + ".output".What could I do in this situation? Thanks in advance for all helps.
My thoughts: Could it be possible for me to read the file name as a string, and add the extension ".output" to the string, and then convert it back to an array of chars? I really think there are easier ways to do this... I feel I am making this more complicated than it really should be. I am not sure... (for open the file, I need it to be char, so I am doing this thing twice at least).
Edited by Darkmist: too in the title is miss-spelled... I meant to type to.