#include <iostream>#include <fstream>#include <vector>#include <string>#include <iterator>#include <algorithm>#include <ctime>#include <cstdlib> int main(){ std::ifstream in_file("words.txt"); if ( in_file.fail() ) { // handle error } std::vector<std::string> v_words; std::copy( std::istream_iterator<std::string>(in_file), std::istream_iterator<std::string>(), std::back_inserter(v_words) ); srand( unsigned ( time(0) ) ); // seed rand() std::string word = v_words[ rand() % v_words.size() ]; // now ''word'' is a word randomly selected from your word list ... // rest of program ... return 0;}
You will have to learn some STL stuff;
fstream
and std::vector
in particular.pkelly83: People have to start somewhere. Drop the arrogance.
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]