简体   繁体   中英

How Can I transform a array of char's in a string in C++?

I have

char array[5] = {'t', 'e', 's', 't'}

I would be

string text = "test"

I can't use any function of string.h to make this proccess.

There's a constructor for that.

std::string text(array);
const int size = 4; string text = ""; char array[size] = {'t', 'e', 's', 't'}; for (int i=0; i<size; i++) { text+=array[i]; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM