Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I put a string value into a charactor array?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
how can I put a string value into a charactor array?

for example,


void main ()
{
string A="hello";
char B[10];


// now I want to put A into char B;
}

tthankx in advance.
 
#include <iostream>
#include <string>

int main()
{
std::string A = &quot;hello&quot;;
char *B = 0;
int iSize = 0;

iSize = A.length();
B = new char[iSize+1];

strcpy( B,A.c_str() );

std::cout << B <<
std::endl;

return 0;

}

Mike L.G.
mlg400@blazemail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top