+ 1

Why does char can't converted to string in Java and also C++? And when I combine it, the program was error?

24th Aug 2018, 4:03 AM
Mas Intan Putri Apriani
Mas Intan Putri Apriani - avatar
3 ответов
+ 2
Ipang Thank you. But why it not happened in Java?
24th Aug 2018, 12:17 PM
Mas Intan Putri Apriani
Mas Intan Putri Apriani - avatar
+ 2
itsintanp I don't know much about Java, but if you link your code in the question maybe other friends who knows Java can help you. I can't help without first seeing the code. Do you know how to attach a code link with your question? Show your code so the problem can be easily identified and solved.
24th Aug 2018, 12:24 PM
Ipang
+ 1
In C++ it is possible, can you show the code that triggers error? anyways, here's an example to demonstrate construction of string from char in C++; #include <string> #include <iostream> int main() { const char *name {"SoloLearn"}; char lang[] {"C++"}; // Constructed from constant char pointer std::string str1 {name}; std::string str2 (name, 4); std::cout << str1 << std::endl << str2 << std::endl ; // Constructed from char array std::string str3 {lang}; std::string str4 (lang, 1); std::cout << str3 << std::endl << str4; } Hth, cmiiw
24th Aug 2018, 4:29 AM
Ipang