[英]How to read in individual characters from txt.file in C++?
I have a txt file that contains individual characters line by line.我有一个 txt 文件,其中包含逐行的单个字符。 I am kind of confused as to how to read that line by line when the getline function takes in string?
当 getline function 接收字符串时,我对如何逐行读取该字符串感到困惑?
Also would it be possible to store char in a vector?也可以将 char 存储在向量中吗? 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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.