How to change the value of a variable in C ++ using the value of this variable in the file?
  • one
    It depends on which variable and depending on which file. Too general question. Specify. - skegg

1 answer 1

We look code.

#include < iostream> #include < fstream> using namespace std; int main() { int val; // записываем ofstream file1("value.txt"); file1 << 42; file1.close(); //закрываем //открываем и читаем ifstream file2("value.txt"); file2 >> val; file2.close(); // закрываем и печатаем значение cout << val << endl; system("pause"); return 0; } 
  • Where is my plus? - embarcadero
  • "We look at the code" and see the complete lack of validation data. - avp
  • I wrote the simplest example to show the basic principle. - embarcadero
  • @embarcadero, read my comment addressed to @ exmp2012, which you should pay attention to after he learned about this way of changing the value of a variable. - avp