Answer the question
In order to leave comments, you need to log in
C++ How to pick up a variable from a.ini file?
Good evening.
There is a task to get a variable from the a.ini file. There is nothing else in the file other than the value of the variable, just a number.
How can this be implemented? ; does not work. int a = fopen ("a.ini", "r")
Answer the question
In order to leave comments, you need to log in
Well, nothing complicated, let's go the simplest way.
#include <fstream> //библиотека файловых потоков
#include <string>
using namespace std;
int main()
{
int value;
string line;
fstream* fileStream;
fileStream = new fstream("c:/file.ini"); //инстанциируем поток и передаем в конструктор путь к файлу
getline(*fileStream, line); //читаем строку первую из файла в string
value = stoi(line); //конвертируем string to int, тут уже на фаш вкус, можно как угодно конвертировать
printf("%d\n", value);
system("pause");
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question