C++ 如何实现输出多个字符串并换行
C++ 如何实现输出多个字符串并换行
当然可以!您可以修改代码来实现输出多个字符串,并在每个字符串输出完成后换行。以下是示例代码:
#include <iostream>
#include <chrono>
#include <thread>
#include <vector>
void delay(int milliseconds) {
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
}
int main() {
std::vector<std::string> strings = {'abcdefg', 'hijklmn', 'opqrst'};
for (const std::string& str : strings) {
for (char c : str) {
std::cout << c;
delay(200); // 等待0.2秒
}
std::cout << std::endl;
}
return 0;
}
这段代码会依次输出字符串 'abcdefg'、'hijklmn' 和 'opqrst',并在输出每个字符串后换行。
希望这对您有所帮助!如有任何其他问题,请随时提问。
原文地址: https://www.cveoy.top/t/topic/OlE 著作权归作者所有。请勿转载和采集!