Hello,
I tried to print an text input file and print the line numbers and the line to stdout. I used std::istreambuf_iterator, but I want to know what its char did it produced. here is the codes that I load the input file.
char * loadFromFile(char * file)
{
//Open file
std::string s;
std::ifstream sourceFile(file);
if (sourceFile)
{
s.assign((std::istreambuf_iterator< char >(sourceFile)),
std::istreambuf_iterator< char >());
}
else {
printf("Eror in openning file [%s].\n", file);
system("pause");
exit(1);
}
return (char*) (s.c_str());
}
when i tried to print the whole char *stream, i got looping until it crashed. Here is the print func.
void print_string(char *ins) {
char *c, *ac;
int i = 1;
for (c = ins; *c != '\0'; i++) {
printf(" %06i : ", i);
for (ac = c; *ac != '\n' || *ac != '\0'; ac++)
putchar(*ac);
putchar('\n');
c = ++ac; // skip the '\n'
}
}
thank in advance