I am trying to save variables in .csv file, even after closing the program and then when opening again to read them from the .csv so, the variables won't reset after closing. The $balance works fine, but $level and $cases's values are 1 every time. They are saved in the .csv, but I can't read them.
#include <iostream>
#include <random>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <sstream>
using namespace std;
int main() {
int $balance = 0, $new_balance, $bet_amount, $random_number, $multiplies, $number_type_number, case_opening;
int $level = 1, $cases = 1, $xp = 0;
int $input_balance = 0, $input_level = 1, $input_cases = 1;
string $free_coins, $bet_type, $number_type_color, $number_type_odd_even, $number_type_row, $bet_type_color;
string $bet_type_halves, $bet_type_third, $bet_type_row;
string $roll_again;
ofstream myFile;
ifstream inputFile;
string line, line1, line2;
/*Useless Code*/
inputFile.open("database.txt");
while (getline(inputFile, line)) {
istringstream ss(line);
ss >> $input_balance;
$balance = $input_balance;
}
while (getline(inputFile, line1)) {
istringstream ss1(line1);
ss1 >> $input_level;
$level = $input_level;
}
while (getline(inputFile, line2)) {
istringstream ss2(line2);
ss2 >> $input_cases;
$cases = $input_cases;
}
do {
/*More Useless Code*/
myFile.open("database.txt");
myFile << $balance << "\t" << $level << "\t" << $cases;
myFile.close();
} while($roll_again == "yes" || $roll_again == "y" || $roll_again == "Yes" || $roll_again == "Y");
}
$balance = 500$ (for example) $level = 5 $cases = 3output after opening the program again:$balance = 500$ $level = 1 $cases = 1I need level and cases to be 5 and 3 in this case, but they are 1 every time. $balance is the only one that saves itself.$before all the variables. I suppose your habit comes from Bash, but adding$before all variable names is not good in C++.