在字符串中建立char *的完整值

时间:2015-01-31 20:19:59

标签: c++

我想知道如何在“Stren”中设置char指针值“d”

char *d;
std::string Stren = *d;

1 个答案:

答案 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';