Software Development Network>> Visual C++>> converting address to string
Given:
int i(99), *pi=&i;
You can output the address directly using:
std::cout << i << ' ' << pi << '\n';
Or you can convert to a string using ostringstream as in:
std::ostringstream ss; ss << pi; std::cout << ss.str() << '\n';
Another way to convert to a string is _ultoa or _ultoa_s, but this does not provide leading zeros:
char Buffer[16]; _ultoa(reinterpret_cast(pi), Buffer, 16); std::cout << Buffer << '\n';
thank you for taking the time to anwer my question, but when I try to make a ostringstream it gives me the following error:
error C2079: 'sc' uses undefined class 'std::basic_ostringstream<_Elem,_Traits,_Alloc>'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
NeederOfVBHelp wrote: I already included the following: #include "stdafx.h" #include <iostream> #include <fstream> What am I missing
I already included the following:
#include
What am I missing
#include <sstream>. Reading the documentation helps occasionally
Thank you for your help, I have another related question if it's not to much bother:
is there way I can convert the address of what a managed handle points to to a string
converting address to string
F. Gsell
Given:
You can output the address directly using:
Or you can convert to a string using ostringstream as in:
Another way to convert to a string is _ultoa or _ultoa_s, but this does not provide leading zeros:
Glenn Wilson
thank you for taking the time to anwer my question, but when I try to make a ostringstream it gives me the following error:
error C2079: 'sc' uses undefined class 'std::basic_ostringstream<_Elem,_Traits,_Alloc>'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
comspy
#include <sstream>. Reading the documentation helps occasionally
Gustis
BobH
Thank you for your help, I have another related question if it's not to much bother:
is there way I can convert the address of what a managed handle points to to a string
TeleRiddler
I already included the following:
#include
"stdafx.h"#include
<iostream>#include
<fstream>What am I missing
Sniper167