-
Small File i/o Problem
For some reason the function below clears my entire file. I don't know if getline() clears what it gets or if something is wrong with my code. Either way, I need to figure out a way to count the lines without wiping out my file. Thanks!
PHP Code:
void lines(){
File.open("data.txt",ios::in);
if (File.is_open()){
while(1){
if (EOF == File.peek()){
break;
}
oflines++;
File.getline(TempInLine, 256);
}
}
File.close();
}
-
What data type is TempInLine? One solution is getline().
std::getline(File, theString);
Kuphryn
-
TempInLine is a char[256] and as far as I can tell, getline() is what I am using...
-
ios::in create a new file every time it's called.
try ios::app if you want to keep adding to the file.