>>What is the wrong with this code
Nothing that I know of, other than it doesn't work

This produces the wrong value, probably because line 10 is only one byte of a 4-byte number.
#include <iostream>
#include <string>
using namespace std ;
int main()
{
char next4[4] = {0};
int n = 123;
memcpy(next4, &n, sizeof(int));
char_traits<char>::char_type ch = next4[4] ;
char_traits<char>::int_type int_val ;
int_val = char_traits<char>::to_int_type (ch) ;
cout << "int_val = " << int_val << "\n";
return 0;
}
Last edited by Ancient Dragon; Sep 18th, 2007 at 8:55 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Offline 21,957 posts
since Aug 2005