#include <iostream>
#include <fstream>
#include <string>
int CountLines( const char* file );
void OutArray( const std::string* s,int iSize );
void PopulateArray( std::string* s,int iSize,const char* file );
int main()
{
std::string* pFile=0;
std::string sPath="";
int iLines=0;
std::cout << "Enter path to file:";
std::getline( std::cin,sPath );
iLines=CountLines( sPath.c_str() );
if( iLines==-1 ) exit( 0 );
pFile=new std::string[iLines];
PopulateArray( pFile,iLines,sPath.c_str() );
OutArray( pFile,iLines );
delete [] pFile;
return 0;
}
void PopulateArray( std::string* s,int iSize,const char* file )
{
std::ifstream inFile;
inFile.open( file );
for( int i=0;i<iSize;i++ )
std::getline( inFile,s );
inFile.close();
}
void OutArray( const std::string* s,int iSize )
{
for( int i=0;i<iSize;i++ )
std::cout << "stringArray[" << i << "]"
<< " = " << s <<
std::endl;
}
int CountLines( const char* file )
{
std::ifstream inFile;
std::string sTemp;
int iNewLines=0;
inFile.open( file );
if( inFile.fail() )
{
std::cout << "No such file exists." <<
std::endl;
return -1;
}
while( !inFile.eof() )
{
std::getline( inFile,sTemp );
++iNewLines;
}
inFile.close();
return iNewLines;
}
//Open a text file and store each line into an array of
//string objects. Mike L.G.
mlg400@blazemail.com