Posted By

lyes on 04/28/19


Tagged

files


Versions (?)

get Word


 / Published in: C++
 

URL: https://www.google.com/url?sa=i&source=images&cd=&cad=rja&uact=8&ved=2ahUKEwi3wd6bxO7gAhUH1BoKHUvBA8gQjRx6BAgBEAU&url=https%3A%2F%2Famalulu.skyrock.com%2Fprofil%2F&psig=AOvVaw3rpw5NXZ9nUhJYuHhQnjIi&ust=1551996526776755

function getWord , retrieving word from a txt file

  1. string getWord(){
  2. string ligne;
  3. ifstream file;
  4. file.open("/home/lyes/Documents/c++/files/dico.txt");
  5. int number = rand() % 323577 + 1;
  6. int i = 0;
  7. while(getline(file,ligne)){
  8. if (i == number){
  9. file.close();
  10. return ligne;
  11. }
  12. i++;
  13. }
  14. file.close();
  15. return "null";
  16.  
  17. }

Report this snippet  

You need to login to post a comment.