2011-04-05 7 views
1

다음 코드가 있는데 char 문자열을 std 문자열로 변환하는 방법을 알지 못합니다. 누군가 나를 도와 줄 수 있습니까?char 문자열을 std 문자열로 변환하는 방법

char Path[STRING_MAX]; 
test->getValue(Config::CODE,Path); 

size_t found; 
cout << "Splitting: " << Path << endl; 
found=Path.find_last_of("/"); 
cout << " folder: " << Path.substr(0,found) << endl; 
cout << " file: " << Path.substr(found+1) << endl; 
+0

올바르게 표시하려면 코드 4 칸을 들여 씁니다. – Swiss

답변

3

사용이 :

std::string sPath(Path); 

나 :

std::string sPath = Path; 

나 :

std::string sPath; 
sPath.assign(Path); 
0

std::string pathstr(Path);std::string의 생성자를 사용하여 변환합니다.

+0

대단히 감사합니다. 그것은 일했다! !! – usustarr

2

C- 문자열 인 경우 Erik이 시연 한 접근법은 정상적으로 작동합니다.

는 C 문자열 이 아닌 그러나 경우가 null 종료 후, 하나는 다음을 수행해야합니다 (하나는 유효한 데이터의 길이를 알고 가정) :

std::string sPath(Path, PathLength); 

나 :

// given std::string sPath 
sPath.assign(Path, PathLength); 
관련 문제