c++操纵器std::ws

std::ws是一个操纵器,它用于跳过输入流中的空白字符(如空格、制表符、换行符等)。在读取数据之前,std::ws会先跳过这些空白字符,确保读取的数据是从下一个非空白字符开始的。

举例:

#include <iostream>
#include <sstream>

int main() {
    std::string input = "   123 456";
    std::istringstream stream(input);
    int num;

    // 使用 std::ws 跳过空格
    stream >> std::ws >> num;

    std::cout << "读取的数字是: " << num << std::endl;  // 输出: 123

    return 0;
}

std::noskipws用于禁用跳过空白字符的功能。

posted @ 2025-10-13 10:32  PKICA  阅读(17)  评论(0)    收藏  举报