This should work:
Code:#include <iostream.h> #include <fstream.h> #include <stdio.h> #include <string.h> void main() { ifstream OpenFile("text.txt"); // Your text file. char ch, temp_str[50]; int cord = 0, last_count = 0; while(!OpenFile.eof()) { OpenFile.get(ch); if (ch == '\n') { temp_str[cord] = '\0'; cout<<temp_str<<"\n"; /* Instead of printing it to your console you could process it however before preceding. */ cord = 0; last_count = 0; } else { temp_str[cord] = ch; cord++; last_count++; } } OpenFile.close(); last_count = last_count - 1; temp_str[last_count] = '\0'; cout<<temp_str<<endl; /* Same as line 23 (to process the current string) just for the last line in the text file since there is no '\n' at the end of the line. */ }