使用 ifstream 读取"*"

Reading "*" with ifstream

本文关键字:读取 ifstream 使用      更新时间:2023-10-16

我正在尝试从文本文件中读取

看起来像

name number1*number2

为什么像这样

Float_t value=0;
ifstream ifs("values.dat");
string line;
while(std::getline(ifs, line)) // read one line from ifs
{
    istringstream iss(line); // access line as a stream
    string dataname;
    ifs >> dataname >> value; // no need to read further

但它无法读取"*数字2"部分,即它只传递给xs number1值。我该如何解决这个问题?

如果运算符周围没有空格,您可以将星号读作单个char

int number1, number2;
char op;
iss >> number1 >> op >> number2;

演示。