Re: converting 1944 to '1','9','4','4'
From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 04/13/04
- Next message: Allan Bruce: "delete this"
- Previous message: Claudio Puviani: "Re: [OT] Proposal to add Interfaces to C++"
- In reply to: x: "converting 1944 to '1','9','4','4'"
- Next in thread: Howard: "Re: converting 1944 to '1','9','4','4'"
- Reply: Howard: "Re: converting 1944 to '1','9','4','4'"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 13 Apr 2004 16:01:00 GMT
"x" <aotemp@hotmail.com> wrote in message
news:26d721d9.0404130708.5b217a1e@posting.google.com...
> converting 1944 to '1','9','4','4'
>
> how can I convert a number such as 1944 to a character array?
>
> thanks!
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
int main()
{
const int value(1944);
std::ostringstream oss;
oss << value;
const std::string s(oss.str());
const char *cs = s.c_str();
const std::string::size_type sz(s.size());
char *array = new char[sz];
std::copy(cs, cs + sz, array);
for(std::string::size_type i = 0; i < sz; ++i)
std::cout << "array[" << i << "] == " << array[i] << '\n';
delete array;
return 0;
}
-Mike
- Next message: Allan Bruce: "delete this"
- Previous message: Claudio Puviani: "Re: [OT] Proposal to add Interfaces to C++"
- In reply to: x: "converting 1944 to '1','9','4','4'"
- Next in thread: Howard: "Re: converting 1944 to '1','9','4','4'"
- Reply: Howard: "Re: converting 1944 to '1','9','4','4'"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]