I done some reading on the seekg and tellg methods, seems fitting.
The code i've written seems to have counted the characters. how could i re-write to count the lines. also the random "line" produced is always equal to character y for some reason..
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string selected = "";
int lines = 0;
ifstream inputFile ("noun.txt");
if(inputFile.is_open() && inputFile != NULL)
{
inputFile.seekg(0, ios::end);
lines = inputFile.tellg();
inputFile.seekg(0, ios::beg);
inputFile.seekg(rand());
inputFile >> selected;
cout << selected << endl;
cout << lines << endl;
}
else
{
cout << "Error with file" << endl;
}
inputFile.close();
return 0;
}