Development/C++
C/C++에서 string을 char[]로
대박단백질
2007. 5. 15. 20:12
String to character array
1. cp = s.c_str(); or s.data();
Pointer cp points to a character array with the same characters as s.
주의!! 리턴 타입이 const char*임, const char*는 char*로 변환이 거의 사용 불가능. ㅡ.ㅡ
2. 그래서 원하는 타입이 char*일때의 아래의 방법을 사용함
string q1;
string str;
int len = Edge[i][0].length();
char *term = new char[len+1];
Edge[i][0].copy( term, len, 0 );
term[len] = '\0';//문자 끝을 알려줌(안그럼 이상한 문자로 채워짐)
CStem::stem(term);//char*타입을 파라미터로 사용하는 메소드
str = term;
q1 = str;
또는...
char* tmptoken = (char*)token.c_str();