Reputation: 11
why this code
char magicData [] = { 0x00i8, 0xfdi8, 0xffi8, 0xfci8, 0x00i8,
0xf3i8, 0xf4i8, 0xf5i8, 0x00i8};
std::string s;
std::istringstream ss(magicData, sizeof(magicData));
while(std::getline(ss, s))
{
std::cout << s << std::endl;
}
don't produce any output? (using stringstream instead of istringstream doesn't help). As result i expect 2 line of string (without 0x00 at end). How to solve it?
Upvotes: 1
Views: 2173
Reputation: 96835
std::istringstream
doesn't have a constructor that takes an array. You're actually calling the constructor that takes a C-style string and an openmode
. All you need for this to work is:
std::istringstream ss(std::string(magic, magic + sizeof(magic)));
Upvotes: 1