SHARE
TWEET

ろれむいぷすむ (Hiragana generator)

Archon Mar 25th, 2013 24 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <fstream>
  5. #include <iterator>
  6. #include <algorithm>
  7. #include <ctime>
  8. #include <cstdlib>
  9.  
  10. #define MAX_NOUNS 3
  11. #define NUM_SENTENCES 10
  12.  
  13. typedef std::vector<std::string> Vec;
  14.  
  15. void readFile(Vec &vec, const char* fileName){
  16.     std::string str;
  17.     std::ifstream file(fileName);
  18.     if (file.is_open()){
  19.         while (file.good()){
  20.             getline(file, str);
  21.             vec.push_back(str);
  22.         }
  23.         file.close();
  24.     }else
  25.         std::cout
  26.             << "Error opening file: "
  27.             << fileName
  28.             << "."
  29.             << std::endl;
  30. }
  31.  
  32. int main(){
  33.     srand(time(0));
  34.  
  35.     Vec nouns, verbs, particles;
  36.    
  37.     readFile(nouns, "nouns.txt");
  38.     readFile(verbs, "verbs.txt");
  39.     readFile(particles, "particles.txt");
  40.  
  41.     if (nouns.empty() || verbs.empty() || particles.empty())
  42.         return 0;
  43.  
  44.     for (int i = 0; i != NUM_SENTENCES; ++i){
  45.  
  46.     int numNouns = rand() % MAX_NOUNS + 1;
  47.     for (int i = 0; i != numNouns; ++i){
  48.         std::cout
  49.             << nouns[rand() % nouns.size()]
  50.             << particles[rand() % particles.size()];
  51.     }
  52.     std::cout
  53.         << verbs[rand() % verbs.size()]
  54.         << "。"
  55.         << std::endl;
  56.  
  57.     }
  58. }
RAW Paste Data
Want to get better at C++?
Learn to code C++ in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top