简体   繁体   中英

How to read in individual characters from txt.file in C++?

I have a txt file that contains individual characters line by line. I am kind of confused as to how to read that line by line when the getline function takes in string?

Also would it be possible to store char in a vector? Or would it still work if I stored those individual characters as strings?

code show as below:

vector<char> res;
int count = 0;

ifstream fin;
fin.open("***.txt");
string str;
while (!fin.eof())
{
   getline(fin, str);
   res[count++] = str;
}
fin.close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM