tags:

views:

78

answers:

3

what is the C++ equivilant to the c function fgets?

I have looked at getline from ifstream, but when it comes to a end of line character, '\n', it terminates at and discards it, I am looking for a function that just terminates at the end line character but adds the end of line character to the char array.

thanks in advance

A: 

You could always put the line terminator there by hand afterwards.

Matti Virkkunen
A: 

Just use C++'s getline and add the newline on yourself.

Billy ONeal
+2  A: 

You can still use std::getline(); just append the newline character yourself. For example,

std::ifstream fs("filename.txt");
std::string s;
std::getline(fs, s);

// Make sure we didn't reach the end or fail before reading the delimiter:
if (fs)
    s.push_back('\n');
James McNellis