Почему моя программа рассматривает действительные числа как строки? [закрыто] ⇐ C++
-
Anonymous
Почему моя программа рассматривает действительные числа как строки? [закрыто]
I'm a C++ beginner and was trying to write a program that wrote variable amount of values to a file, before summing them and displaying the total. However, instead of summing the values, my program acts like they are a string and appends them instead. Does anyone have any advice?
void calculateTotalValue() { //Declare an internal name for an input file. ifstream valuesFile; //Declare a variable to hold the values that will be combined. double currentValue = 0; //Declare a variable to hold the total value. double totalValue = 0; //Open a file named values.dat on the disk. valuesFile.open("values.dat"); //Determine if the file was opened. if (!valuesFile.is_open()) { "\nUnable to open a file!\n"; } else { //Calculate the total value. while (!valuesFile.eof()) { valuesFile >> currentValue; totalValue = totalValue + currentValue; } //Display the total value. cout
Источник: https://stackoverflow.com/questions/780 ... as-strings
I'm a C++ beginner and was trying to write a program that wrote variable amount of values to a file, before summing them and displaying the total. However, instead of summing the values, my program acts like they are a string and appends them instead. Does anyone have any advice?
void calculateTotalValue() { //Declare an internal name for an input file. ifstream valuesFile; //Declare a variable to hold the values that will be combined. double currentValue = 0; //Declare a variable to hold the total value. double totalValue = 0; //Open a file named values.dat on the disk. valuesFile.open("values.dat"); //Determine if the file was opened. if (!valuesFile.is_open()) { "\nUnable to open a file!\n"; } else { //Calculate the total value. while (!valuesFile.eof()) { valuesFile >> currentValue; totalValue = totalValue + currentValue; } //Display the total value. cout
Источник: https://stackoverflow.com/questions/780 ... as-strings
Мобильная версия