#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <chrono>
using namespace std;
using namespace std::chrono;
// 预定义一些单词供游戏使用
const string words[] = {"apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew"};
const int wordCount = sizeof(words) / sizeof(words[0]);
int main() {
srand(static_cast<unsigned int>(time(0))); // 初始化随机数种子
while (true) {
// 随机选择一个单词
string selectedWord = words[rand() % wordCount];
cout << "Type the following word as fast as you can: " << selectedWord << endl;
auto start = high_resolution_clock::now(); // 记录开始时间
string userInput;
cin >> userInput;
auto end = high_resolution_clock::now(); // 记录结束时间
duration<double> elapsed = end - start; // 计算
标签:const,游戏,int,wordCount,打字,c++,words,sizeof,include
From: https://blog.csdn.net/vehiclevjv/article/details/145232144