滥用 istream&get

Misusing istream& get

本文关键字:get istream 滥用      更新时间:2023-10-16

我正在尝试制作一种从外部文件中提取电子邮件信息并将其存储在字符串中的方法。我正在使用 .get 提取字符,但我的调试器说:没有重载函数的实例与参数列表匹配。它还说它无法将第三个参数从 const char[2] 转换为 char。这似乎是一个快速解决方案,但我一直在玩弄参数,似乎无法弄清楚出了什么问题。

current->email_data.sent 是指向字符数组的指针。

另外,我不确定为什么我的代码在粘贴到此处时不会缩进。

int Classify::Load_email(char filename[]) {
email_node * current;
current = email_head;  
ifstream source_file(filename);
if(email_head)
{
    while(current->next) {
        current = current->next;
    }
}
else {
    email_head = new email_node;
}
while(!source_file.eof()) {
    source_file.get(current->email_data.sent, 200, "|");
}
};

basic_istream::get 的三参数重载中,最后一个参数是单个字符,而不是字符串。将"|"替换为 '|'