F
F
Firewoll2020-10-23 15:02:25
C++ / C#
Firewoll, 2020-10-23 15:02:25

Set variable value from txt?

How to assign a value from a txt file to a variable, like this I tried to take only one letter first.

std::ifstream fin("C:/ProgramData/Data/name.txt");
  std::string name;
  name = fin.get();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Firewoll, 2020-10-23
@Firewoll

std::ifstream fin("C:/ProgramData/Data/name.txt");
std::string name;
fin >> name

N
none7, 2020-10-23
@none7

That's the way it should be. If you want to read the entire file into a line, see the example .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question