Creating a String from a Single Character in C
In C , it is possible to create a string from a single character. Here are several methods to achieve this:
<code class="cpp">char c = 34; std::string s(1, c); std::cout << s << std::endl; // Outputs: "</code>
<code class="cpp">char c = 34; std::string s{c}; std::cout << s << std::endl; // Outputs: "</code>
<code class="cpp">char c = 34; std::string s; s.push_back(c); std::cout << s << std::endl; // Outputs: "</code>
The above is the detailed content of How Can I Create a String from a Single Character in C ?. For more information, please follow other related articles on the PHP Chinese website!