爆炸时调用'get line'没有匹配功能

No matching function for call to 'get line' while exploding

本文关键字:功能 line get 调用      更新时间:2023-10-16
使用此

代码时调用"getline"时没有匹配函数:

ifstream myfile;
string line;
string line2;
myfile.open("example.txt");
while (! myfile.eof() )
{
    getline (myfile, line);
    getline (line, line2, '|');
    cout<<line2;
}

在示例中.txt我有这样的信息:

1|Name1|21|170
2|Name2|34|168

等。。。

我真的很想把线弄到| 字符...

我尝试了一些爆炸函数,但它们只是字符串类型,但我需要:

第一个是国际

第二个是字符

第 3 和第 4 个浮动。

我想做的真的很复杂,我无法很好地解释它。我希望有人能理解我。

getline 接收模板basic_istream字符串的实例作为第一个参数,不符合该要求。

您可以使用字符串流:

#include <sstream>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
    string line;
    string line2;
    ifstream myfile("test/test.txt");
    while (getline(myfile, line))
    {
        stringstream sline(line);
        while (getline(sline, line2, '|'))
            cout << line2 << endl;
    }
    return 0;
}