C++ getline method not working

前端 未结 4 2001
借酒劲吻你
借酒劲吻你 2021-01-24 23:41

I\'m sorry but I\'m quite new to C++ but not programming in general. So I tried to make a simple encryption/decryption. However when I added the modification to my previous code

4条回答
  •  终归单人心
    2021-01-25 00:09

    As other stated already, the formatted input (using in >> value) start skipping space abd stop when they are done. Typically this results in leaving some whitespace around. When switching between formatted and unformatted input you typically want to get rid of leading space. Doing so can easily be done using the std::ws manipulator:

    if (std::getline(std::cin >> std::ws, line)) {
        ...
    }
    

提交回复
热议问题