使用 ifstream 读取"*"
Reading "*" with ifstream
我正在尝试从文本文件中读取
看起来像 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;
演示。
相关文章:
- ifstream文件在从行中读取时被清除
- std::ifstream::read 不会读取所有 512 字节,并设置 EOF 和失败位
- 虽然循环不读取整个 ifstream 文件
- std::ifstream 在读取文件中最后一项时设置 eofbit,但仅在读取数值类型时发生
- ifstream 尝试读取 9 到 13 之间的无符号字符时非常奇怪的行为
- ifstream 读取的字符与文件中写入的字符不同
- 为什么ifstream没有读取任何内容
- 从带有 std::ifstream::read() 的文件中读取 int 遍历 char * 二进制数据
- 将 ifstream 读取到 char* 以进行 int 和字符串转换
- ifstream 不读取第一行
- ifstream 不读取缓冲区
- 如何在 c++ 中读取/写入无符号数组到 ifstream/ostream?
- 从 ifstream 读取 int 到 2-D 动态数组
- C++ : 如何在使用 getline() 和 ifstream 对象从文件中读取一行时跳过第一个空格?
- C++如何附加ifstream以将多个文件读取为一个大文件
- 使用 c++ ifstream 读取文本文件问题
- 将 ifstream 文件和每一行读取到数组中
- 尝试使用 ifstream 读取数据后显示不正确的数字
- 函数不读取 ifstream 文件
- 如何从未签名的char中读取ifstream