I am trying to implement a program that reads from a text file, a line at a time. I am able to read the first line using the getline function but now how would I go to the next line. Here is my code so far
#ifndef H_SearchSort
#define H_SearchSort
#include<iostream>
#include<string>
using namespace std;
class SearchSort
{
// int Record_Size;
// string Record_Arr[]; // array to store the data
// string list_Read;
public:
void StoreInArr(string);
};
#endif
#include <iostream>
#include<fstream>
#include "SearchSort.h"
using namespace std;
void SearchSort::StoreInArr(string line_Read)
{
// int Array_Size = 0;
//string Array[Array_Size];
int i = 1;
/*** ifstream inFile("list.txt");
if (inFile.good())
{
while(!inFile.eof())
{
getline(inFile, list_Read);
} ***/
//string *line_Read = &list_Read;
cout<<line_Read<<endl;
return;
}
#include "SearchSort.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string line;
SearchSort xyz;
ifstream inFile;
inFile.open("list.txt");
getline(inFile,line, '\n');
xyz.StoreInArr(line);
system ("PAUSE");
return 0;
}
I thought of making a string pointer that points to the variable 'line' which has the first sentence and then increment the pointer to point to next address but I realized that variable 'line' is just storing the read in sentence and not really pointing to the sentence in the text file.
Please someone help me.
Thanks.

New Topic/Question
Reply




MultiQuote



|