DEV Community

海前 王
海前 王

Posted on

string cin

#include <iostream>
#include <limits>
#include <iostream>
#include <fstream>
#include <iostream>

int main() {
    std::cout << "Enter some text: ";

    // 忽略输入流中的前 5 个字符

    std::string remainingInput;
    std::cin.ignore(1);
    std::getline(std::cin, remainingInput);


    std::cout << "Remaining input: " << remainingInput << std::endl;

    std::cin.putback(remainingInput[0]);

    getline(std::cin,remainingInput);
    std::cout << "Remaining input: " << remainingInput << std::endl;

    return 0;
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)