![]() |
Bonjour et bienvenu par les États-Unis à la UNIX et Linux Forums! Merci de votre visite et vous joindre à notre communauté mondiale.
|
|
google unix.com
|
|||||||
| Forums | S'inscrire | Forum Rules | Liens | Albums | FAQ | Liste des membres | Calendrier | Recherche | Aujourd'hui, les postes | Marquer les forums comme lus |
| High Level Programming Posez vos questions à propos de C, C + +, Java, SQL, et d'autres langages de programmation ici. |
Plus d'UNIX et Linux Forum Sujets Vous trouverez peut-être utile
|
||||
| Fil | Thread Starter | Forum | Réponses | Last Post |
| Un programme pour tracer l'exécution d'un autre programme | jiten_hegde | High Level Programming | 3 | 08-19-2008 06:26 AM |
| strtok équivalent en perl | JISHA | De programmation et de script Shell | 1 | 05-06-2008 04:38 AM |
| Regardign strtok () pour diriger la sortie 2-D string array | SankarV | High Level Programming | 3 | 04-28-2008 10:48 AM |
| Strtok fonction .... | Tanvirk | Linux | 3 | 01-24-2008 10:16 AM |
| mieux que strtok? | annie | High Level Programming | 7 | 10-05-2005 03:01 PM |
![]() |
|
|
LinkBack | Thread Tools | Recherche sur ce Thread | Rate Thread | Modes d'affichage |
|
|
|
||||
|
Comment utiliser strtok deux fois dans le même programme?
Code:
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;
Code:
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 Comment puis-je tokenizer str2 maintenant? Merci |
|
||||
|
Je ne comprends pas la nécessité d'utiliser strtok () pour votre problème. Quoi qu'il en soit, la réponse est juste dans tout le manuel pour strtok (3):
Citation:
Code:
// ...
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()," ");
// ...
|
![]() |
| Bookmarks |
| Thread Tools | Recherche sur ce Thread |
| Modes d'affichage | Rate this thread |
|
|