Code:
#include <string> //for std::string
#include <algorithm> //for std::for_each
struct print_as_int
{
void operator() (const char & ch) { std::cout << (static_cast<int>(ch)) << ' '; }
};
int main ()
{
char ch;
ifstream infile;
infile.open("testing.txt");
std::string buf;
while(std::getline(infile, buf))
{
std::for_each(buf.begin(), buf.end(), print_as_int());
}
infile.close( );
return 0;
}
*edit* Ah, DavidP makes a good point. *edit*
Code:
// . . . .
print_as_int func_ob;
std::for_each(buf.begin(), buf.end(), func_ob);
func_ob('\n');
//. . . . .
Except for one extra '\n' at the end, I think that's the idea.