如何在C++中读取txt.file中的单个字符

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

本文关键字:file 单个 字符 txt 读取 C++      更新时间:2024-05-24

我有一个txt文件,它逐行包含各个字符。我有点困惑,当getline函数接收字符串时,如何逐行读取?

还有可能将字符存储在向量中吗?或者,如果我将这些单独的字符存储为字符串,它还会起作用吗?

代码显示如下:

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