【问题标题】:unwanted skipping of whitespaces不必要的空格跳过
【发布时间】:2015-05-15 14:54:49
【问题描述】:

我正在使用它来读取输入:

istringstream iss;
string typ, data;
char c1, c2;
iss >> skipws >> c1 >> typ >> noskipws >> c2 >> data;

输入行可以看起来像这样" #text Markup used in this document is compatible with " 不带引号

我想要实现的是在我的代码变量数据之后将包含"Markup used in this document is compatible with "

但是,即使在我指定我不希望它使用 noskipws 跳过空格之后,此代码也会忽略单词 Markup 之后的所有内容

【问题讨论】:

    标签: c++ istringstream


    【解决方案1】:

    如果您阅读例如this std::noskipws reference你会看到的

    [...] 禁用格式化输入函数跳过前导空格

    它并没有真正跳过输入中的混合空格,读入字符串总是在空格处停止。

    相反,您可以使用std::getline 来获取该行的其余部分。

    【讨论】:

      猜你喜欢
      • 2021-09-19
      • 1970-01-01
      • 2014-03-28
      • 1970-01-01
      • 1970-01-01
      • 2019-07-20
      • 1970-01-01
      • 2020-04-21
      • 2019-06-04
      相关资源
      最近更新 更多