このコードを見て、c_strがポインター先のアドレスを指しているのは分かりますが、c++ plusというサイトでは
c_strはポインターを返すと説明されています。
実際にはポインター先のアドレスを示したいときに、もちろんポインターはアドレスを示しているのですが、ポインターを返すという表現は適切なのでしょうか?
ちょっと気になったので質問させていただきました。
コード // strings and c-strings #include <iostream> #include <cstring> #include <string> int main () { std::string str ("Please split this sentence into tokens"); char * cstr = new char [str.length()+1]; std::strcpy (cstr, str.c_str()); // cstr now contains a c-string copy of str char * p = std::strtok (cstr," "); while (p!=0) { std::cout << p << '\n'; p = std::strtok(NULL," "); } delete[] cstr; return 0; }
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。