I'm trying to open a file and save the information there in an array of chars, however I'm not getting it. To save in a string use this:
int main(){
string line1;
ifstream myfile;
myfile.open("example.txt");
if(!myfile){
cout<<"Unable to open the file."<<endl;
exit(0);
}
while(getline(myfile,line1)){
ReadFile(myfile);
}
}
And It works. When I use an array of chars, I code like this:
int main(){
int size=100;
char line1[size];
ifstream myfile;
myfile.open("example.txt");
if(!myfile){
cout<<"Unable to open the file."<<endl;
exit(0);
}
while(myfile.peek()!EOF){
line1[size]->ReadFile();
}
}
The function ReadFile is this:
void ReadFile(ifstream &is){
char aux[100];
is.getline(aux,100);
}