Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1595 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  streamstring problem

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

streamstring problem

n°1138379
cricri_
Posté le 02-07-2005 à 21:33:56  profilanswer
 

J'ai un truc bizarre avec ce code :
 

Code :
  1. /* ------------------------------------------------------------------------- */
  2. bool CNumMidasCtrl::ParseLine( string& szLine)
  3. /* ------------------------------------------------------------------------- */
  4. {
  5. string::size_type  pos = 0;
  6. string::iterator  it  = szLine.begin();
  7. stringstream   sstr;
  8. string      * tszValPt[] = { &m_szX, &m_szY, &m_szZ, &m_szA, &m_szC, NULL};
  9. string     tszNomPt[] = { "X=", "Y=", "Z=", "A=", "C=" }; // no NULL !!    
  10. size_t     j = 0;
  11. if ( szLine.empty())
  12.  return false;
  13. // Extraction values
  14. while ( tszValPt[j] != NULL) {
  15.  if ( (pos = szLine.find( tszNomPt[j])) == string::npos)
  16.   return false;
  17.  sstr.str("" );
  18.  it  = szLine.begin();
  19.  sstr << &it[pos + 2];
  20.  sstr >> *tszValPt[j];
  21. //  MessageBox( (*tszValPt[j]).c_str());
  22.  ++j;
  23. }
  24. return true;
  25. }


 
szLine :
#1 CH=2 AMP=14.44 X=1344.888 Y=340.024  Z=1423.099 C=351.278  A=1393.488
 
La dernière valeur, C est null dans ce cas ...
Si je modifie l'ordre d'analyse avin d'analyser X, Y, Z, C, A, ça fonctionne.
 
Mais dans le désordre, ça ne fonctionne pas, je récupère rien ...
 
obligé de remplacer :
sstr << &it[pos + 2];
par  
sstr << &it[pos + 2] << ' ';
 
bizarre, non ?
 

mood
Publicité
Posté le 02-07-2005 à 21:33:56  profilanswer
 

n°1138382
Taz
bisounours-codeur
Posté le 02-07-2005 à 21:39:09  profilanswer
 

entre la notation hongroise et le code manquant, c'est illisible ton truc.
 
mais bon, pour faire simple
 
string& szLine
 
perdue, une string n'est pas terminée par un '\0'
 
donc &it[pos + 2] est un char* mal formé.

n°1138504
cricri_
Posté le 03-07-2005 à 10:01:26  profilanswer
 

Ok, je comprends, mais comment faut-il que je le forme ce char * alors ?
 
Et quel code manquant ? il ne manque rien là, si ?
 
sinon pour la notation ... j'avoue trouver pratique de connaitre le type de la variable s'il est "simple", mais bon ... tu ferais comment ?

n°1138508
Taz
bisounours-codeur
Posté le 03-07-2005 à 10:25:12  profilanswer
 

non. t'as juste à extraire une sous-chaine.
 
j'aime pas ta notation, mais là, elle est erronée.

n°1138525
cricri_
Posté le 03-07-2005 à 11:42:27  profilanswer
 

ok, je trouvais plus simple d'extraire les sous-chaines grace à l'opérateur << car il n'y a pas à rechercher la fin de la sous-chaine, mais bon, comme ce n'est pas correct ...
J'ai corrigé ma notation ;)
Merci  :jap:

n°1138526
Taz
bisounours-codeur
Posté le 03-07-2005 à 11:45:10  profilanswer
 

pour une sous-chaine : voir les différents constructeurs de std::string.

n°1138536
cricri_
Posté le 03-07-2005 à 12:29:28  profilanswer
 

vi, j'ai vu, mais comme la chaine destination existe déjà j'ai utilisé substr()
 :jap:


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  streamstring problem

 

Sujets relatifs
Problem MySQL et Phpmyadmin >HELP SVP !!<problem batch fichier dont le nom varie
Problem de cssgetopt problem
Problem de reponse provenant d un socket (timing?)[c#] Problem: affichage d'une progressBar
[newbie]problem pour l'execution des applet[JSP] Problem connexion à Mysql
Problem pour afficher fenêtre Windowsproblem avec mysql/innodb
Plus de sujets relatifs à : streamstring problem


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR