저는 C++을 처음 사용하고 아직 모든 개념을 아직 파악하지 못했기 때문에이 함수가 작동하지 않는 이유에 당혹 스럽습니다. 현재 집에 없기 때문에 컴파일러 오류를 게시 할 수 없습니다. 집에 도착하자 마자 바로 처리 할 것입니다.상수 문자 포인터를 반환하면 오류가 발생합니다.
여기에 함수가 있습니다.
const char * ConvertToChar(std::string input1, std::string input2) {
// Create a string that you want converted
std::stringstream ss;
// Streams the two strings together
ss << input1 << input2;
// outputs it into a string
std::string msg = ss.str();
//Creating the character the string will go in; be sure it is large enough so you don't overflow the array
cont char * cstr[80];
//Copies the string into the char array. Thus allowing it to be used elsewhere.
strcpy(cstr, msg.c_str());
return * cstr;
}
const char *를 반환하기 위해 두 문자열을 연결하고 변환하도록 만들어졌습니다. 그 이유는 그것을 사용하고자하는 함수는 const char 포인터가 전달되어야하기 때문입니다.
문자열을 훨씬 쉽게 연결할 수 있습니다 :'string1 + string2'. 당신은 전체'stringstream' 물건을 필요로하지 않습니다. –