Originally Posted by
BluePudding
I should've probably explained that I need it to be able to go to any line at any given time.
This is simple enough. Just store each line into an array or a vector. Make sure you use a '\n' as a delimeter in getline() as that will be the end of each line.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
int main() {
std::ifstream inFile("myInstructions.txt");
std::vector<std::string> instructions;
while(inFile) {
instructions.push_back(*(new std::string));
std::getline(inFile, instructions[instructions.size()-1], '\n');
}
std::cout << "Here are the instructions:\n";
for(std::vector<std::string>::iterator i = instructions.begin();
i < instructions.end(); i++) {
std::cout << *i << '\n';
}
std::cin.get();
return 0;
}
/* Output:
Here are the instructions:
Do homework.
Go to sleep.
Wake up.
Take shower.
Get dressed.
Eat breakfast.
Go to school.
*/