A
Alex Vinokur
Hi,
// --------------------
#include <iostream>
#include <iomanip>
int main()
{
char data[5];
data[0] = 'a';
data[1] = 5;
data[2] = 'b';
data[3] = 10;
data[4] = 0;
for (std::size_t i = 0; i < sizeof(data); i++)
{
char ch = data;
if (isprint(static_cast<int>(ch)) != 0)
{
std::cout << ch;
}
else
{
std::cout << "\\" << std:ct << static_cast<int>(ch) << std::dec;
}
}
std::cout << std::endl;
return 0;
}
// ------------------
Output:
a\5b\12\0
Is it possible to get the same or similar output without loop in the
program?
Thanks,
Alex
// --------------------
#include <iostream>
#include <iomanip>
int main()
{
char data[5];
data[0] = 'a';
data[1] = 5;
data[2] = 'b';
data[3] = 10;
data[4] = 0;
for (std::size_t i = 0; i < sizeof(data); i++)
{
char ch = data;
if (isprint(static_cast<int>(ch)) != 0)
{
std::cout << ch;
}
else
{
std::cout << "\\" << std:ct << static_cast<int>(ch) << std::dec;
}
}
std::cout << std::endl;
return 0;
}
// ------------------
Output:
a\5b\12\0
Is it possible to get the same or similar output without loop in the
program?
Thanks,
Alex