Advertisement
Guest User

Untitled

a guest
May 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. // RWtxt.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <fstream>
  6. #include <iostream>
  7. #include <string>
  8. #include <vector>
  9.  
  10. using namespace std;
  11. string div(string s,bool ignoreDiv) {
  12. //string s = "scott>=tiger>=mushroom";
  13. string delimiter = "`";
  14.  
  15. size_t pos = 0;
  16. string token;
  17. while ((pos = s.find(delimiter)) != string::npos) {
  18. token = s.substr(0, pos);
  19. //cout << token << endl;
  20. //cout << s << endl;
  21. s.erase(0, pos + delimiter.length());
  22. }
  23. //cout << s << endl;
  24. //cout << token;
  25. if (ignoreDiv) {
  26. return token;
  27. }
  28. return s;
  29. }
  30. int main()
  31. {
  32. vector<string> answrs;
  33. vector<string> userAnswrs;
  34. string line;
  35. ifstream read("template.txt");
  36. //lineCount -> Number of questions in the file.
  37. int lineCount = 0;
  38. if (read.is_open())
  39. {
  40. while (getline(read, line))
  41. {
  42. //cout << line << endl;
  43. answrs.push_back(div(line,false));
  44. answrs.emplace_back("\n");
  45. //cout << line << '\n';
  46. cout << "Question:" << div(line, true) << endl << "Answers: " << div(line, false) << endl << "You Answer: ";
  47. string temp;
  48. cin >> temp;
  49. userAnswrs.push_back(temp);
  50. userAnswrs.emplace_back("\n");
  51.  
  52. lineCount++;
  53. }
  54. read.close();
  55. cout <<"Number of lines read: "<< lineCount << endl;
  56. }
  57. else cout << "Unable to open file";
  58.  
  59.  
  60.  
  61. return 0;
  62. }
  63.  
  64. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  65. // Debug program: F5 or Debug > Start Debugging menu
  66.  
  67. // Tips for Getting Started:
  68. // 1. Use the Solution Explorer window to add/manage files
  69. // 2. Use the Team Explorer window to connect to source control
  70. // 3. Use the Output window to see build output and other messages
  71. // 4. Use the Error List window to view errors
  72. // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  73. // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
  74. /*
  75. bool brk = false;
  76. while (!brk) {
  77. string values;
  78. cout << "Please Enter Values: ";
  79. cin >> values;
  80. cout << values<<endl;
  81. brk = true;
  82. }
  83. */
  84.  
  85. /*
  86. ofstream results("results.txt");
  87. if (results.is_open())
  88. {
  89. int i = 0;
  90. while (!results.eof()) {
  91.  
  92. results << "Question "<<i<<": ";
  93. results << "\n";
  94. results.close();
  95. i++
  96. }
  97. }
  98. else cout << "Can not open";
  99. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement