Ok so I am learning C++. I want check to see how many files exist for a bank account program for class. My method of doing this is to run a loop to run through and attempt to open "0000000001.txt" to see if it is valid, then "0000000002.txt", and so on. The difficult part is the numbers have the leading zeros( it needs to be a total of 10 digits before ".txt".
double num_of_accounts() {
double number_of_accounts = 0;
double count = 0;
double testFor = 0000000000;
ofstream ifile;
string filename = "0000000000";
for (count = 0; 0 < /*MAX_NUMBER_OF_ACCOUNTS*/ 5; count++){
ifile.open(filename + ".txt");
if (ifile) { number_of_accounts++; }
// I would like to increment the number in the filename by 1 here
} // END of for (count = 0; 0 < MAX_NUMBER_OF_ACCOUNTS; count++){
return number_of_accounts;
}
Or possibly a way to format the double to be 10 digits long and then convert to string using to_string()? I tried googling it but I don't know if I am using the wrong keywords.
This is on win console if that helps.
Thank you