IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

VC++ .NET Discussion :

[.NET]réécriture d'un fichier a partir d'une list box


Sujet :

VC++ .NET

  1. #1
    Membre �clair� Avatar de scorpking
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    232
    D�tails du profil
    Informations personnelles :
    �ge : 38
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 232
    Par d�faut [.NET]réécriture d'un fichier a partir d'une list box
    bonjour j'ai fais une recherche et lu la FAQ mais tout ce que j'ai trouv� est pour visual basic
    j'aimerai r�cup�rer le contenu d'une listbox pour l'�crir dans un fichier mais la r�cup�ration me pose un probl�me
    j'ai essayer une boucle for pour r�ccup�rer ligne par ligne mais le getcount pour la taille de la listbox de la FAQ n'existe pas sur mon programme

    voila la partie de mon programe

    private: System::Void button5_Click(System::Object * sender, System::EventArgs * e)
    {
    String* path =
    this->openFileDialog1->FileName;
    CString fichier1 (path);
    string fichier2(fichier1);
    ofstream fic(fichier2.c_str());
    // taille= this ->listBox2->;
    for(int i=1;i<taille;i++)
    {
    String* ligne;
    ligne = Convert::ToString(listBox2->Items->get_Item(i));
    fic << ligne;
    }
    fic.close();
    MessageBox (NULL, "r��criture du fichier termin�", NULL, NULL);

    }

  2. #2
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    wahou ... le roi du m�lange ...
    un ptit peu de MFC par ci, un peu de C++.Net par l�, sans oublier une pointe de C++ avec un soupcon de stl

    Je te propose une version en C++/CLI, tu ne devrais pas avoir trop de mal � l'adapter en C++.Net 1.x
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
                     System::IO::StreamWriter ^sw = gcnew System::IO::StreamWriter("fichier.txt");
                     for each (String ^s in listBox1->Items)
                         sw->WriteLine(s);
                     sw->Close();

  3. #3
    Membre �clair� Avatar de scorpking
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    232
    D�tails du profil
    Informations personnelles :
    �ge : 38
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 232
    Par d�faut
    merci je vais essayer de traduire en .net
    et pour le m�lange je ne fais qu'apliquer ce que j'aprend en cour

    edit: bon la traduction c'est pas encore �a j'arrive a voir ou tu veut en venir mais au d�bug �a donne rien ya pas un moyen simple de connaitre e nombre de ligne de la listBox?
    ou alor simplement de forcer la selection de la derniere ligne de la listbox pour en rep�r� le num�ro

  4. #4
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    traduit pour le MC++, ca donnerait quelque chose comme ca
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
                     System::IO::StreamWriter * sw = new System::IO::StreamWriter("fichier.txt");
                     for (int i=0;i < listBox1->Items->Count;i++)
                         sw->WriteLine(listBox1->Items->get_Item(i));
                     sw->Close();
    Par contre ... si on t'apprend � tout m�langer, vous devez avoir du mal � vous y retrouver

  5. #5
    Membre �clair� Avatar de scorpking
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    232
    D�tails du profil
    Informations personnelles :
    �ge : 38
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 232
    Par d�faut
    merci pour la traduction j'avai oublier le items en cherchant le Count �a marche �a
    mais le probl�me c'est d�plac� maintenant faut que je passe d'une s�rie de code ascii en exa d�cimal ecris dans une string � un fichier ecris en hexa tout cours j'ai fais une boucle pour r�cup�r�r code par code mais il me manque le passage de string � ascii j'essai pour l'instant de passer par une char les probl�mes quand y'en a plus y'en a encore
    bref comment passer d'un code hexa ecris dans un char � un caractere hexa ecris dans mon fichier

    pour les cour vu qu'on a jamais apris l� diff�rence entre le c++.net le c++ ou le cli on s'en sort et moi c'est que ma premiere ann�e de programation

  6. #6
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    ce code fonctionne pourtant chez moi, de plus, l'objet Item est une ListBox.ObjectCollection et dans msdn, on voit bien qu'il dispose de la propri�t� count http://msdn.microsoft.com/library/fr...mberstopic.asp

  7. #7
    Membre �clair� Avatar de scorpking
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    232
    D�tails du profil
    Informations personnelles :
    �ge : 38
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 232
    Par d�faut
    oups j'ai pas editer assez vite tu peux effacer ton message et le mien d�sol�

  8. #8
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    tu peux repr�ciser la question ?

    tu cherches � convertir quoi en quoi ? donne un exemple

  9. #9
    Membre �clair� Avatar de scorpking
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    232
    D�tails du profil
    Informations personnelles :
    �ge : 38
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 232
    Par d�faut
    en fait j'essai de trouver tout seul l� c pour �a que j'ai pas pr�cis�
    mais j'ai un ligne sous cette forme
    52 49 46 46 ba d8 00 00 57 41 56 45 66 6d 74 20
    qui sont les codes ascii d'un fichier son et je doit r��crire le fichier en r�utilisant les codes ascii pour que mon fichier son soit lisible extraire code par code ok mais c'est pr�s que �a coince

  10. #10
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    bon, je te laisse chercher alors, revient si ca coince

  11. #11
    Membre �clair� Avatar de scorpking
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    232
    D�tails du profil
    Informations personnelles :
    �ge : 38
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 232
    Par d�faut
    ouai ben depuis tout a l'heure je continue de coincer j'ai toutes les solution pour obtenir le code ascii ou pour ecrir une lettre ou autre a partir de son code ascii en d�cimal mais je sais pas comment faire a partir de ce code enregistr� dans un int ou un char celui l� meme que je doit r�implanter dans mon fichier

  12. #12
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    bon, je comprends rien

    Dis moi si je me trompe.

    Tu as un fichier � lire, et tu voudrais afficher sa repr�sentation hexad�cimale ?

  13. #13
    Membre �clair� Avatar de scorpking
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    232
    D�tails du profil
    Informations personnelles :
    �ge : 38
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 232
    Par d�faut
    �a c'est fais
    mais maintenant que je l'ai affich� et modifi� je doit la r�inplanter maistenant que j'ai copier ma ligne en hexa que j'ai montr� plus haut je doit r�implanter le code hexa dans un nouveau fichier et non sous format text et je n'arrive pas a passer du code hexa que je sort de la ligne au vrai code hexa que recconais lordi (car il s'agit soit de fichier sons soit de fichier image)

  14. #14
    R�dacteur
    Avatar de nico-pyright(c)
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    6 414
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 6 414
    Par d�faut
    il suffit de faire l'inverse de ce que tu as fait, montre ton code

  15. #15
    Membre �clair� Avatar de scorpking
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    232
    D�tails du profil
    Informations personnelles :
    �ge : 38
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 232
    Par d�faut
    hexeditgraph

    private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
    {
    this->openFileDialog1->ShowDialog();
    }
    private: System::Void button2_Click(System::Object * sender, System::EventArgs * e)
    {
    this->listBox2->Items->Clear();
    this->listBox3->Items->Clear();
    this->listBox4->Items->Clear();
    String* path =
    this->openFileDialog1->FileName;
    CString fichier1 (path);
    string fichier2(fichier1);
    staticint taille;

    taille = monfichier->ouverture(fichier2);
    if(taille==-1)
    {
    String* message="le fichier est illisible";
    this->listBox4->Items->Add(message);
    }
    else
    {
    this->listBox4->Items->Add(Convert::ToString(taille));
    for(int i=0;i<taille;i=i+16)
    {
    if(monfichier->lireligne())
    {
    string ligneHexa1 = monfichier->getLigneHexa();
    char ligneHexa2[100];
    strcpy (ligneHexa2, ligneHexa1.c_str() );
    String *ligneHexa =
    new String(ligneHexa2);
    this->listBox2->Items->Add(ligneHexa);
    string ligneAscii1 = monfichier->getLigneAscii();
    char ligneAscii2[100];
    strcpy (ligneAscii2, ligneAscii1.c_str() );
    String *ligneAscii =
    new String(ligneAscii2);
    this->listBox3->Items->Add(ligneAscii);

    }
    }
    }
    monfichier->fermeture();
    this->button5->Enabled=true;
    }

    private: System::Void button3_Click(System::Object * sender, System::EventArgs * e)
    {
    String* ligne;
    int courant = this->listBox2->SelectedIndex;
    ligne =
    this->textBox1->Text;
    listBox2->Items->set_Item(courant,ligne);
    }
    private: System::Void button4_Click(System::Object * sender, System::EventArgs * e)
    {
    String* ligne;
    int courant = this->listBox2->SelectedIndex;
    ligne = Convert::ToString(listBox2->Items->get_Item(courant));
    this->textBox1->Text = ligne;
    this->button3->Enabled=true;
    }
    private: System::Void button5_Click(System::Object * sender, System::EventArgs * e)
    {
    String* path =
    this->openFileDialog1->FileName;
    CString fichier1 (path);
    string fichier2(fichier1);
    ofstream fic(fichier2.c_str());
    //ofstream fic("tempfic.txt");
    int taille= this->listBox2->Items->Count;
    for(int i=0;i<taille;i++)
    {
    String* ligne=Convert::ToString(listBox2->Items->get_Item(i));
    CString ligne2(ligne);
    string ligne3(ligne2);
    for(int j=0; j<46;j=j+3)
    {
    int k=2;
    string code1(ligne3,j,k-j)
    char code2(
    //c'est l� que �a coince
    }
    fic.close();
    MessageBox (NULL, "r��criture du fichier termin�", NULL, NULL);

    }
    private: System::Void openFileDialog1_FileOk_1(System::Object * sender, System::ComponentModel::CancelEventArgs * e)
    {
    this->listBox1->Items->Clear();
    String* path =
    this->openFileDialog1->FileName;
    this->listBox1->Items->Add(path);
    this->button2->Enabled=true;
    }
    private: System::Void listBox2_SelectedIndexChanged(System::Object * sender, System::EventArgs * e)
    {
    this->button4->Enabled=true;

    }
    };
    }
    hex.cpp

    int
    CHex::ouverture(string fichier)
    {
    entree.open(fichier.c_str(),ios_base::binary);
    if(entree.good())
    {
    entree.seekg(0,ios_base::end);
    TailleFichier=entree.tellg();
    entree.seekg(0,ios_base::beg);
    return TailleFichier;
    }
    cout <<" le fichier est ilisible"<< endl;
    return -1;
    }
    bool CHex::lireligne(void)
    {
    if(entree.read((char *)ligne, 16))
    returntrue;
    // else if(entree.seekg(0,ios_base::beg)=TailleFichier)
    // cout <<endl<<endl<<"fin de fichier";
    else
    returnfalse;
    }
    string CHex::getLigneHexa(
    void)
    {
    string buffer;

    for(int i=0;i<16;i++)
    {
    ostringstream oss;
    oss.width(2);
    oss.fill('0');
    oss << hex << (
    int)ligne[i] <<" ";

    buffer.append(oss.str());
    }

    return buffer;
    }

    string CHex::getLigneAscii(
    void)
    {
    string ascii;
    for(int i=0;i<16;i++)
    {
    if(ligne[i]< 0x20 || ligne[i] >= 0x80)
    {
    ligne[i]='.';
    }
    ostringstream oss;
    oss<<ligne[i];
    ascii.append(oss.str());
    }
    return ascii;
    }
    int CHex::donneTaille(void)
    {
    return TailleFichier;
    }
    void CHex::fermeture()
    {
    entree.clear();
    entree.close();

    }
    voila ou j'en suis

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. copier des fichiers a partir d'une liste
    Par NicaeaCivitas dans le forum Windows
    R�ponses: 2
    Dernier message: 11/07/2017, 15h23
  2. R�ponses: 6
    Dernier message: 29/08/2010, 20h59
  3. [XL-2007] ouvrir un fichier PDF � partir d'une liste
    Par croky23 dans le forum Macros et VBA Excel
    R�ponses: 12
    Dernier message: 11/09/2009, 15h53
  4. R�ponses: 6
    Dernier message: 08/09/2009, 14h35
  5. [WD14] Ajout dans un fichier a partir d'une liste
    Par mero007 dans le forum WinDev
    R�ponses: 1
    Dernier message: 20/07/2009, 15h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo