Write your question here.
I was trying to make an program that lets you test your typing speed, but ran in to a problem.
I want to use a seperate file (.txt or sth) to store strings of random words, like an array.
Thank you!
P.s. Im on my phone, so i dont have the current code, but i might put it in later ;).
#include <fstream>
#include <iostream>
#include <random>
#include <vector>
int main()
{
// Opens the file:
std::ifstream fileStream( "someWords.txt");
if (!fileStream)
{
std::cout << "File couldn't opened!\n";
exit(1);
}
// Reads all words from file into a vector:
std::vector<std::string> wordList;
std::string word;
while (fileStream >> word)
{
wordList.push_back(word);
}
// Sets up C++ random facilities:
std::default_random_engine e( std::random_device{}());
std::uniform_int_distribution<> d(0, wordList.size()-1);
// print a random word from the vector:
std::cout << wordList[d(e)];
exit(0);
}