string

closed account (Djvk92yv)
hello.how to the first three charcters from char array into string array?

closed account (SECMoG1T)
Assuming you mean copying

1
2
3
4
5
6
7
char *p="abagagaga";
 std::string s(p,3);
 std::cout<<s;

char arr[6]={'a','g','k','l','p'};
std::string str(arr,3);
std::cout<<str;


that should work.
Did you check the reference pages?

Several ways to do it:

1) Use the 5th form of std::string's constructor:
http://www.cplusplus.com/reference/string/string/string/

2) Use the 4th form of append (if the string is empty)
http://www.cplusplus.com/reference/string/string/append

3) Use the 4th form of string::assign
http://www.cplusplus.com/reference/string/string/assign/




Last edited on
Topic archived. No new replies allowed.