![]() |
Helloやアメリカ合衆国へようこそ! UNIXおよびLinuxフォーラム!訪問し、当社のグローバルコミュニティに参加いただきありがとうございます。
|
|
Googleのunix.com
|
|||||||
| 高レベルのプログラミング は、 C 、 C + +についての質問の投稿は、 Java 、 SQL 、および他のプログラミング言語です。 |
その他のUNIXおよびLinuxフォーラムトピックは参考にすること
|
||||
| スレッド | スレッドスターター | フォーラム | 返信 | 最後の投稿 |
| プログラムが別のプログラムの実行をトレースする | jiten_hegde | 高レベルのプログラミング | 3 | 2008年8月19日 05:26午前 |
| strtok同等ではperl | jisha | シェルプログラミングとスクリプティング | 1 | 2008年5月6日 03:38午前 |
| Regardign strtok ( ) 2 - Dの文字列配列に出力演出 | SankarV | 高レベルのプログラミング | 3 | 2008年4月28日 09:48午前 |
| Strtok機能.... | Tanvirk | リナックス | 3 | 2008年1月24日 10:16午前 |
| strtokよりも良い方法ですか? | アニー | 高レベルのプログラミング | 7 | 2005年10月5日 02:01午後 |
![]() |
|
|
LinkBack | スレッドツール | このスレッドを検索 | スレッドを評価 | 表示モード |
|
|
|
||||
|
どのように2回、同じプログラムでstrtokを使用するか?
コード:
string str1(" 1 2 3 4 512543 ");
string str2;
if(str2.empty())
str2=str1;
cout << "str2:" <<str2 <<endl;
p1=strtok((char *)str1.c_str()," ");
while(p1)
{
v1.push_back(atoi(p1));
cout << "val of p1 " << p1 << endl;
p1=strtok(NULL," ");
}
cout << "size of v1 " << v1.size() <<endl;
p2=strtok((char *)str2.c_str()," ");
cout << "str2:" <<str2 <<endl;
while(p2)
{
v2.push_back(atoi(p2));
cout << "val of p2 " << p2 <<endl;
p2=strtok(NULL," ");
}
cout << "size of v2" << v2.size() <<endl;
コード:
str2: 1 2 3 4 512543 val of p1 1 val of p1 2 val of p1 3 val of p1 4 val of p1 512543 size of v1 5 str2: 1234512543 val of p2 1 after tok p2 size of v21 str2二つのトークンはどのようにすることができますか? ありがとう |
|
||||
|
私はあなたの問題( ) strtokを使用することの必要性を理解することはありません。いずれにせよ、その答えは、 strtok ( 3 )のマニュアルは、すべてを超えています:
引用:
コード:
// ...
string str1(" 1 2 3 4 512543 ");
string str2;
if(str2.empty())
{
str2=str1;
str2.insert(0, ""); // now, you tell me why this apparently solves your problem!
}
cout << "str2:" <<str2 <<endl;
p1=strtok((char *)str1.c_str()," ");
// ...
|