Ifstream With Struct vector | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Ifstream With Struct vector

Hey, im searching for a way to safe a vector in a file. you're thinking it's quite easy but here's a part of the code struct user { string name; int id; }; vector<user> userlist; I can get an input from the user and I can output the saved name and id but how can I read a .txt file? saving is quite easy I already got it.

11th Jul 2018, 7:07 AM
Talha Hameed
Talha Hameed - avatar
2 Answers
+ 1
Make a method in your struct to read a single user object, and in a for loop, read data fron the file inside a temp object and push this object inside the vector. You will get your data.
11th Jul 2018, 12:35 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar