U
Ural Mutlu
Hi,
I have an array of int's and a string. I am trying to copy the int array
into the string but I haven't been successful. The only solution I can think
of is strcpy or memcpy.
I wrote the following test program but in the example below str is empty.
I thought of using itoa() in the stdlib.h but itoa() must be obsolete, gcc
doesn't find the function.
Any suggestions?
OS: linux
compiler: gcc v:4.1.1
#include <iostream>
#include <string>
using namespace std;
int main() {
string str("");
int i[2]={0,0};
strncpy((char*)str.c_str(),(char*)i, sizeof(i));
//memcpy((void*)str.c_str(),(void*)i, sizeof(i));
cout<<str<<endl;
return 0;
}
Regards
I have an array of int's and a string. I am trying to copy the int array
into the string but I haven't been successful. The only solution I can think
of is strcpy or memcpy.
I wrote the following test program but in the example below str is empty.
I thought of using itoa() in the stdlib.h but itoa() must be obsolete, gcc
doesn't find the function.
Any suggestions?
OS: linux
compiler: gcc v:4.1.1
#include <iostream>
#include <string>
using namespace std;
int main() {
string str("");
int i[2]={0,0};
strncpy((char*)str.c_str(),(char*)i, sizeof(i));
//memcpy((void*)str.c_str(),(void*)i, sizeof(i));
cout<<str<<endl;
return 0;
}
Regards