Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- // Define class called textLines (used to store list of lines)
- class textLines
- {
- public:
- // Main Constructor
- textLines(ifstream& myfile1){
- pointer = new string[stringsize];
- if (myfile1.fail()) {
- cout << "File failed to open.n";
- exit(1);
- }
- else
- for (int index = 0; index < stringsize; index++) {
- myfile1 >> pointer[index];
- }
- }
- // Constructor that takes an integer parameter that sets the size of an empty list.
- textLines(int){
- pointer = new string[0];
- }
- // Deconstructor
- ~textLines(){
- delete[] pointer;
- }
- void printArray();
- private:
- ifstream infile;
- ofstream outfile;
- static int stringsize;
- string* pointer;
- };
- // Begin Main Function
- int main(){
- string myfile = "Lab3Text.txt";
- ifstream infile(myfile);
- textLines text(infile);
- text.printArray();
- return 0;
- }
- // End Main
- int textLines::stringsize = 1000;
- void textLines::printArray(){
- for (int index = 0; index < stringsize; index++) {
- cout << pointer[index];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement