Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // RWtxt.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include "pch.h"
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- string div(string s,bool ignoreDiv) {
- //string s = "scott>=tiger>=mushroom";
- string delimiter = "`";
- size_t pos = 0;
- string token;
- while ((pos = s.find(delimiter)) != string::npos) {
- token = s.substr(0, pos);
- //cout << token << endl;
- //cout << s << endl;
- s.erase(0, pos + delimiter.length());
- }
- //cout << s << endl;
- //cout << token;
- if (ignoreDiv) {
- return token;
- }
- return s;
- }
- int main()
- {
- vector<string> answrs;
- vector<string> userAnswrs;
- string line;
- ifstream read("template.txt");
- //lineCount -> Number of questions in the file.
- int lineCount = 0;
- if (read.is_open())
- {
- while (getline(read, line))
- {
- //cout << line << endl;
- answrs.push_back(div(line,false));
- answrs.emplace_back("\n");
- //cout << line << '\n';
- cout << "Question:" << div(line, true) << endl << "Answers: " << div(line, false) << endl << "You Answer: ";
- string temp;
- cin >> temp;
- userAnswrs.push_back(temp);
- userAnswrs.emplace_back("\n");
- lineCount++;
- }
- read.close();
- cout <<"Number of lines read: "<< lineCount << endl;
- }
- else cout << "Unable to open file";
- return 0;
- }
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
- // Debug program: F5 or Debug > Start Debugging menu
- // Tips for Getting Started:
- // 1. Use the Solution Explorer window to add/manage files
- // 2. Use the Team Explorer window to connect to source control
- // 3. Use the Output window to see build output and other messages
- // 4. Use the Error List window to view errors
- // 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
- // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
- /*
- bool brk = false;
- while (!brk) {
- string values;
- cout << "Please Enter Values: ";
- cin >> values;
- cout << values<<endl;
- brk = true;
- }
- */
- /*
- ofstream results("results.txt");
- if (results.is_open())
- {
- int i = 0;
- while (!results.eof()) {
- results << "Question "<<i<<": ";
- results << "\n";
- results.close();
- i++
- }
- }
- else cout << "Can not open";
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement