I have a Linux file descriptor (from socket), and I want to read one line. How to do it in C++?

7 points

I have a Linux file descriptor (from socket), and I want to read one line at a time. How to do it in C++?

Created by ranipoojax 40 weeks 6 days ago
  Tags:

Answer(s):

3 points

 

<cpp>
char newline = '\n';
file fd
;
initialize
(fd);
string line;
char c;
while( newline != (c = readchar(fd)) ) {
 line
.append(c);
}
</cpp>

Something like that.

Created by Thomas j

Post your Answer

  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options