Injecting string to 'cin'

前端 未结 3 1945
长发绾君心
长发绾君心 2020-12-09 17:36

I have a function that reads user input from std::cin, and I want to write a unittest that inserts some strings into std::cin, such that later extraction from std::cin will

3条回答
  •  粉色の甜心
    2020-12-09 17:56

    Instead of screwing around with cin, you can have your program accept a general std::istream&. When running normally, just pass it cin. During a unit test, pass it an I/O stream of your own creation.

提交回复
热议问题