按字符输出的字符来模拟打字效果

时间:2013-06-02 16:07:01

标签: c++

如果你想在C ++程序中输出每个字符的字符,模拟打字动作,会怎么样?

2 个答案:

答案 0 :(得分:3)

试试这个:(C ++ 11)

#include <iostream>
#include <thread>
#include <chrono>

int main() {
    std::string s = "Hello!";

    for (const auto c : s) {
        std::cout << c << std::flush;
        std::this_thread::sleep_for(std::chrono::milliseconds(500));
    }
    std::cout << std::endl;
}

答案 1 :(得分:0)

您仍然可以在要编写的每个字符之间使用lib C中的usleep(ms)函数。它有效。