Advertisement
Guest User

Untitled

a guest
May 18th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. // ifstream.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. #include <vector>
  9. using namespace std;
  10.  
  11.  
  12. int counter(char* FileName);
  13. vector<string> ReadIn(char * FileName, int length);
  14.  
  15. int main(int argc,const char* argv[])
  16. {
  17.     char fille[256];
  18.     cin.getline(fille,256);
  19.     int  lines = counter(fille);
  20.     vector<string> vectors = ReadIn(fille,lines);
  21.     cout << lines;
  22.     for (int i = 0 ; i < lines ; i++)
  23.     {
  24.         cout << vectors.at(i) << " \n";
  25.     }
  26.     system("PAUSE");
  27.     return 0;
  28. }
  29.  
  30. int counter(char* FileName)
  31. {
  32.     ifstream inFile;
  33.     int counter = 0;
  34.     char fileLine[256];
  35.     inFile.open(FileName);
  36.     while(!inFile.eof())
  37.     {
  38.         counter++;
  39.         inFile.getline(fileLine,256);
  40.  
  41.     }
  42.     counter+1;
  43.     return counter;
  44. }
  45. vector<string> ReadIn(char * FileName, int length)
  46. {
  47.     vector <string> vector1(length);
  48.     ifstream inFile;
  49.     char fileLine[256];
  50.     inFile.open(FileName);
  51.     while(!inFile.eof())
  52.     {
  53.         int i = 0;
  54.         inFile.getline(fileLine,256);
  55.         vector1.at(i)=fileLine;
  56.         cout << vector1.at(i);
  57.         i++;
  58.     }
  59.     return vector1;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement