使用>>运算符

求婚

任何人都可以请我向我解释代码中以下几行的含义

 while (ss >> temp)

    std::string str = "123:234:56:91";   

    for (int i=0; i<str.length(); i++)
    {
        if (str[i] == ':')
           str[i] = ' ';
    }

    vector<int> array;
    stringstream ss(str);
    int temp;
    while (ss >> temp)
       array.push_back(temp); 
用户名

因为ss是流,所以>>重载以从流中进行格式化读取,具体取决于右侧操作数的类型。

因此,while(ss >> temp)将从中读取空格分隔的整数stringstream这就是为什么您将上面的' :'替换为' '的原因当以布尔值求值时,如果false在流的末尾读取了整数,则为true

有关更多详细信息,请参见此处的示例

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章