stream - c++ iostream, stringstream termination -


i programming simly tcp server, , i've got problem termination of stream.

i'm receiving data, defined end of data combination \r\n ,but stream terminating on first \0 in data.

bool read(char &chr_glob, stringstream &ss ){     char chr;     char buffer[buffer_size];     while (!ss.get(chr)){         ss.clear();         recv(c, buffer, buffer_size, 0);         ss<<buffer;     }     chr_glob = chr     if ( chr == '\r' ){         char tmp = ss.peek();         if ( tmp == '\n'){             ss.get(chr_glob);             return false;         }     }      return true; } 

i trying use iostream , i've compilation problem, , don't know how fix it.

in file included /usr/include/c++/4.8/iostream:40:0, robot.cpp:7: /usr/include/c++/4.8/istream: in function ‘int main(int, char**)’: /usr/include/c++/4.8/istream:830:7: error: ‘std::basic_iostream<_chart, _traits>::basic_iostream() [with _chart = char; _traits = std::char_traits<char>]’ protected basic_iostream() ^ robot.cpp:148:14: error: within context iostream ss; ^ 

the stream terminating on first \0 in data.

ss<<buffer; 

expects null-terminated c string (the null used determine data length). use write binary data:

size = recv(c, buffer, buffer_size, 0); ss.write(buffer, size); 

i trying use iostream , i've compilation problem, , don't know how fix it.

iostream base class. cannot instantiated directly. use stringstream did.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -