How could I make a program read a file line-by-line? Not string-by-sting; line-by-line.
Printable View
How could I make a program read a file line-by-line? Not string-by-sting; line-by-line.
you wanna make a progam that reads a complete line into a string, i mean until end of lineQuote:
Originally posted by CodeMonkey
How could I make a program read a file line-by-line? Not string-by-sting; line-by-line.
then you should use:
i'm not sure about the arguments order, i mean, i used fgets but dont know if thats the right orderCode:FILE *inp=fopen("input.dat","rt");
char s[200][202];
int k=0;
while(!feof(inp)){
fgets(s[k],inp,200);
k++;
}
i used fgets(destination, sourcefile, maxlenght);
you should check the help for getting the correct order
// reading a text file
#include <iostream.h>
#include <fstream.h> //input with files
int main () {
char buffer[256];
ifstream examplefile ("example.txt"); //set file for reading.
if (! examplefile.is_open()) //error when opening file
{ cout << "Error opening file"; exit (1); }
while (! examplefile.eof() ) //while its not the end of file
{
examplefile.getline (buffer,100); //just like cin but from file
cout << buffer << endl;
}
return 0;
}