Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. // Define class called textLines (used to store list of lines)
  8. class textLines
  9. {
  10. public:
  11. // Main Constructor
  12. textLines(ifstream& myfile1){
  13.  
  14. pointer = new string[stringsize];
  15.  
  16. if (myfile1.fail()) {
  17. cout << "File failed to open.n";
  18. exit(1);
  19. }
  20. else
  21. for (int index = 0; index < stringsize; index++) {
  22. myfile1 >> pointer[index];
  23. }
  24. }
  25. // Constructor that takes an integer parameter that sets the size of an empty list.
  26. textLines(int){
  27. pointer = new string[0];
  28. }
  29. // Deconstructor
  30. ~textLines(){
  31. delete[] pointer;
  32. }
  33.  
  34. void printArray();
  35.  
  36.  
  37. private:
  38. ifstream infile;
  39. ofstream outfile;
  40. static int stringsize;
  41. string* pointer;
  42. };
  43.  
  44. // Begin Main Function
  45. int main(){
  46.  
  47. string myfile = "Lab3Text.txt";
  48.  
  49. ifstream infile(myfile);
  50.  
  51. textLines text(infile);
  52. text.printArray();
  53.  
  54.  
  55. return 0;
  56. }
  57. // End Main
  58.  
  59.  
  60. int textLines::stringsize = 1000;
  61.  
  62. void textLines::printArray(){
  63.  
  64. for (int index = 0; index < stringsize; index++) {
  65. cout << pointer[index];
  66. }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement