I have following code to read a text file line by line and store data in a string*
variable:
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main(){
// open a file in read mode.
ifstream infile;
infile.open("iris.csv");
// read file line by line and store here:
string *strlist;
int count =0;
for (string line; getline(infile, line); ) {
strlist[count] = line;
count++;
}
infile.close();
//print all lines:
for (int i=0; i<count; i++){
cout << strlist[i];
}
}
Will above work or will there be some memory problem. Do I need to make a new
string before assigning a value strlist[i]=line
?
I did not try it fearing that an error may cause data damage. Thanks for your help.