我想知道如何在“Stren”中设置char指针值“d”
char *d;
std::string Stren = *d;
答案 0 :(得分:1)
单个字符的构造函数需要填充计数。
std::string Stern( 1, *d ); // Stores a single character pointed by d.
例如:
char *d = "this is an example";
std::string Stern( 1, *d ); // Stern is now "t";
std::string Stern2( d ); // Stern is now "this is an example";
std::cout << d << std::endl; // Outputs "this is an example" followed by '\n'
std::cout << *d << std::endl; // Outputs "t" followed by '\n';