繁体   English   中英

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

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

我有一个 txt 文件,其中包含逐行的单个字符。 当 getline function 接收字符串时,我对如何逐行读取该字符串感到困惑?

也可以将 char 存储在向量中吗? 或者如果我将这些单独的字符存储为字符串,它仍然可以工作吗?

代码显示如下:

vector<char> res;
int count = 0;

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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