/*
Hey internet,
I am trying to write a program that adds a number to the end of a filename.
*/
// the first pass works great the second pass does not
Hey internet,
I am trying to write a program that adds a number to the end of a filename.
*/
Code:
#include <ostream>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
int dayNum = 0; // Day number.
string filenameString; // Holder for sequential filename suffix.
ostringstream convert; // Holder for int daynum to string conversion.
string repFilename = "FILENAME"; //f Name of File.
cout << endl;
cout << "Day Number: "; // Get the day number.
cin >> dayNum;
cout << endl;
convert << dayNum; // Assing dayNum to covert.
filenameString = convert.str(); // Change dayNum from int to string.
filenameString = "_DAY_" + filenameString;
// Add "_day_" to dayNum suffix.
filenameString = repFilename + filenameString + ".txt";
// Add file name + dayNum suffix.
cout <<"\n";
cout << "File name is = " << filenameString; // TEST 1
cout <<"\n";
// TEST 2. should make filename = FILENAME_DAY_2.txt.
dayNum++; // Assign dayNum + 1 to covert.
convert << dayNum; // Assing dayNum to covert.
filenameString = convert.str(); // Change dayNum from int to string.
filenameString = "_day_" + filenameString;
// Add "_day_" to dayNum suffix.
filenameString = repFilename + filenameString + ".txt";
// Add file name + dayNum suffix.
cout <<"\n";
cout << "NEW File name is = " << filenameString.c_str(); // TEST
cout <<"\n";
cout <<"\n";
// but the file name is = FILENAME_day_12.txt
} // END main.
// the first pass works great the second pass does not