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

C++ Discussion :

Problème et AVC : _wfopen_s


Sujet :

C++

  1. #181
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut
    Par donc :
    L"" ===> u8"" !


    Exemple :
    std::wstring sj; ===> std::string sj; (u8)

  2. #182
    Expert éminent sénior
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 068
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 068
    Points : 12 111
    Points
    12 111
    Par défaut
    'L' est une MACRO, je sais pas ce que fait 'u8'.
    Il faut juste faire en sorte de pas mélanger les variables d'un type et celles d'un autre.
    Utilisez au maximum std::wstring, mais "std::runtime_error" ne le supporte pas, d'où la nécessité de convertir les std::wstring en std::string.
    => créer une MACRO pour la construction des messages d'erreur qui fera la conversion std::wstring en std::string.

    Gardez le reste du code en std::wstring.

  3. #183
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    L n'est pas une macro, c'est un préfixe pour constante.
    Je crois que u8 aussi dans les versions les plus récentes du langage.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  4. #184
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut Adapatations pour aphasique
    Bonjour,
    Je suis l'orthophoniste de Laurent_B_. Il a subi un AVC il y a plusieurs années. Il a une aphasie, c'est-à-dire des troubles du langage (difficultés pour parler, lire, écrire).
    Il utilise le narrateur de l'ordinateur pour lire, mais ça reste difficile pour lui de comprendre, quand les phrases sont longues ou compliquées. Il est aussi fatigable et a donc du mal à traiter un long texte.
    Pour écrire, il ne peut pas faire de phrases complètes: les verbes ne viennent pas.
    Il vous remercie d'avoir la gentillesse d'essayer de répondre à ses questions. Pourriez-vous faire des réponses plus courtes et des phrases plus simples ? ça l'aiderait encore davantage.
    Merci d'avance.

  5. #185
    Expert éminent sénior
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 068
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 068
    Points : 12 111
    Points
    12 111
    Par défaut
    Utiliser 'L' le plus possible et n'utiliser les 'u8' que dans les messages d'erreur lancer avec std::runtime_error.
    Si des chaines de caractère std::wstring doivent passer dans les messages d'erreur, utiliser :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(variableContenantUneWString)
    Courage et désolé pour les longs pavés.

  6. #186
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    On doit pouvoir faire une fonction pour ça, non?
    Un truc du genre:
    Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    std::string wstr_to_u8(std::wstring uneWString)
    {
    	return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(uneWString);
    }
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  7. #187
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    std::string wstr_to_u8(std::wstring uneWString)
    {
    	return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(uneWString);
    }
    ou
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(variableContenantUneWString)
    Unix : oui !
    Mais pas Windows ! (codecvt ???)

    ----------------------------------------------

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    const std::vector<std::wstring> lire_fichierTxt(std::wstring const& nomFichier, std::wstring marqueurFinDeLigne)
    {
        std::string contenuFichier{ u8"" };
        std::string ligneCourante{ u8"" };
        std::vector<std::wstring> retVal{};
     
        ifstream fichier{ nomFichier };
        if (!fichier)
        {
            throw std::runtime_error("Fichier impossible à ouvrir.");
        }
     
        while (getline(fichier, ligneCourante, u8'\n'))
        {
            contenuFichier += ligneCourante + u8'\n';
        }
     
        if (contenuFichier == u8"")
        {
            //throw std::runtime_error(L"Fichier " + (std::wstring)nomFichier + L" est vide."); // Marche par !!!
            throw std::runtime_error("Fichier est vide.");
            //throw std::runtime_error("Le fichier '" + std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(nomFichier) + "' est vide.");
        }
        wstring_convert<codecvt_utf8_utf16<wchar_t>, wchar_t> convertiseur;
        std::wstring converti = convertiseur.from_bytes(contenuFichier);
        rtrim(converti);
        while (std::size_t pos = converti.find(L'\n'/*marqueurFinDeLigne*/))
        {
            retVal.push_back(converti.substr(0, pos));
            converti = converti.substr(pos + 1/*marqueurFinDeLigne.length()*/);
            if (pos == std::wstring::npos)
                break;
        }
        return retVal;
    }
    et :
    exemple : you /t s "e:\Séries.[]\+++\D\Deadwind.[2018- Netflix]"
    ici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
        while (std::size_t pos = converti.find(L'\n'/*marqueurFinDeLigne*/))
        {
            retVal.push_back(converti.substr(0, pos));
            converti = converti.substr(pos + 1/*marqueurFinDeLigne.length()*/);
            if (pos == std::wstring::npos)
                break;
        }
    Créée par.txt
    ------------------
    Jari Olavi Rantala, Rike Jokela
    Kirsi Porkka
    et :
    Nom : Capture.PNG
Affichages : 300
Taille : 2,8 Ko

    ", " et ", " ???

    ------------------------------------------------------

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    void Serie::afficher_Creee_par(std::wstring& c, std::wstring const& nomFichier, std::vector<std::wstring>&c_p) const
    {
        assert((c == createdBy_filename) && L"Erreur !!! Créée par... !");
        c_p = lire_fichierTxt(nomFichier, L", ");
        assert((c_p.size() != 0));
    }
    Mais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    class Serie
    {
    ...
        std::vector<std::wstring> creee_par;
        std::vector<std::wstring> en_relation_avec;
    ...
    };
    ...
    class Cinema
    {
    ...
    	std::vector<std::wstring> de;
    	std::vector<std::wstring> par;
    ...
    };
    regrouper en creee_par, en_relation_avec, de, par... ???

    -----------------------------------------

    Merci beaucoup

  8. #188
    Expert éminent sénior
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 068
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 068
    Points : 12 111
    Points
    12 111
    Par défaut
    Citation Envoyé par Laurent_B_ Voir le message
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    std::string wstr_to_u8(std::wstring uneWString)
    {
    	return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(uneWString);
    }
    ou
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(variableContenantUneWString)
    Unix : oui !
    Mais pas Windows ! (codecvt ???)
    La formule avec "td::wstring_convert<std::codecvt_utf8<wchar_t>>..." est bien trop longue et peu explicite.
    Créez la fonction "wstr_to_u8" qui sera bien plus simple à appeler et lisible dans votre code.

    Donc l'exemple d'utilisation du code deviendra :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    throw std::runtime_error("Le fichier '" + wstr_to_u8(nomFichier) + "' est vide.");
    Quel est le problème avec Windows ?

    Citation Envoyé par Laurent_B_ Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    const std::vector<std::wstring> lire_fichierTxt(std::wstring const& nomFichier, std::wstring marqueurFinDeLigne)
    {
    ...
    }
    Modification avec utilisation de la fonction "wstr_to_u8", renommage du 2ème paramètre pour qu'il corresponde à son utilisation et son utilisation effective:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    const std::vector<std::wstring> lire_fichierTxt(std::wstring const& nomFichier, std::wstring separeteur)
    {
        std::string contenuFichier{ u8"" };
        std::string ligneCourante{ u8"" };
        std::vector<std::wstring> retVal{};
    
        ifstream fichier{ nomFichier };
        if (!fichier)
        {
            throw std::runtime_error("Fichier '" + wstr_to_u8(nomFichier) + "' impossible à ouvrir.");
        }
    
        while (getline(fichier, ligneCourante, u8'\n'))
        {
            contenuFichier += ligneCourante + u8'\n';
        }
    
        if (contenuFichier == u8"")
        {
            throw std::runtime_error("Le fichier '" + wstr_to_u8(nomFichier) + "' est vide.");
        }
        wstring_convert<codecvt_utf8_utf16<wchar_t>, wchar_t> convertiseur;
        std::wstring converti = convertiseur.from_bytes(contenuFichier);
        rtrim(converti);
        while (std::size_t pos = converti.find(separeteur)
        {
            retVal.push_back(converti.substr(0, pos));
            converti = converti.substr(pos + separeteur.length());
            if (pos == std::wstring::npos)
                break;
        }
        return retVal;
    }

    Citation Envoyé par Laurent_B_ Voir le message
    et :
    exemple : you /t s "e:\Séries.[]\+++\D\Deadwind.[2018- Netflix]"
    ici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
        while (std::size_t pos = converti.find(L'\n'/*marqueurFinDeLigne*/))
        {
            retVal.push_back(converti.substr(0, pos));
            converti = converti.substr(pos + 1/*marqueurFinDeLigne.length()*/);
            if (pos == std::wstring::npos)
                break;
        }

    et :
    Nom : Capture.PNG
Affichages : 300
Taille : 2,8 Ko

    ", " et ", " ???
    Vous n'utilisez pas "correctement" le second paramètre.
    Si vous voulez que "\n" soit aussi un séparateur, convertissez le second paramètre en un vector de std::wstring et changez la boucle pour qu'elle cherche le premier séparateur présent.

    à l'arrache:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    const std::vector<std::wstring> lire_fichierTxt(std::wstring const& nomFichier, std::vector<std::wstring> separeteurs)
    {
    ...
        bool found = false;
    
        do
        {
            found = false;
            size_t pos_found = std::string::npos;
            std::wstring sep_found = "";
    
            for( auto&& sep : separateurs)
            {
                std::size_t pos = converti.find(separeteur);
                if(pos != std::wstring::npos && (!found || pos_found > pos))
                {
                    pos_found = pos;
                    found = true;
                    sep_found = sep;
                }
            }
    
            if(found)
            {
                retVal.push_back(converti.substr(0, pos_found));
                converti = converti.substr(pos_found + sep_found.length());
            }
        }while(found)
    
        if(converti.length()>0)
        {
            retVal.push_back(converti);
        }
    }
    (Il doit avoir plus direct avec des librairies ou dans les algorithmes de la STL)
    Vous aurez aussi en sortie :
    Jari Olavi Rantala, Rike Jokela, Kirsi Porkka
    Car l'une de vos routines doit, semble-t-il, ajouter un , entre chaque élément retourné par "lire_fichierTxt".

    Vous pouvez peut-être changer le contenu du fichier "Créée par.txt" plutôt que de modifier le type du 2ème paramètre de la fonction "lire_fichierTxt":
    soit :
    ------------------
    Jari Olavi Rantala
    Rike Jokela
    Kirsi Porkka
    ------------------
    ------------------
    (à lire avec lire_fichierTxt(...,L"\n"))
    ------------------
    soit :
    ------------------
    Jari Olavi Rantala, Rike Jokela, Kirsi Porkka
    ------------------
    ------------------
    (à lire avec lire_fichierTxt(...,L", "))
    ------------------

    Citation Envoyé par Laurent_B_ Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    void Serie::afficher_Creee_par(std::wstring& c, std::wstring const& nomFichier, std::vector<std::wstring>&c_p) const
    {
        assert((c == createdBy_filename) && L"Erreur !!! Créée par... !");
        c_p = lire_fichierTxt(nomFichier, L", ");
        assert((c_p.size() != 0));
    }
    Mais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    class Serie
    {
    ...
        std::vector<std::wstring> creee_par;
        std::vector<std::wstring> en_relation_avec;
    ...
    };
    ...
    class Cinema
    {
    ...
    	std::vector<std::wstring> de;
    	std::vector<std::wstring> par;
    ...
    };
    regrouper en creee_par, en_relation_avec, de, par... ???
    "afficher_Creee_par" ,'a toujours aucun sens, il ne fait pas ce qu'indique son nom.
    Je pense qu'il serait très préférable d'avoir que quelques fonctions généralistes que les fonctions spécifiques appelleraient :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    void afficher_contenu_formate(std::wstring const& nomFichier, std::wstring prefixe; std::vector<std::wstring> separateurs)
    {
        std::vector<std::wstring> liste_a_afficher = lire_fichierTxt(nomFichier, separateurs);
     
        ....(partie qui affiche les données en utilisant le paramètre "prefixe" pour l'afficher avant la liste récupérée)
    }
     
    void Serie::afficher_Creee_par() const{
        afficher_contenu_formate(createdBy_filename,L"Créée pars :", {L", "})
    }

  9. #189
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut
    La formule avec "td::wstring_convert<std::codecvt_utf8<wchar_t>>..." est bien trop longue et peu explicite.
    Créez la fonction "wstr_to_u8" qui sera bien plus simple à appeler et lisible dans votre code.

    Donc l'exemple d'utilisation du code deviendra :
    Marche pas !!!
    Et :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    throw std::runtime_error("Le fichier '" + wstr_to_u8(nomFichier) + "' est vide.");
    Marche pas !!!

    Médinoc :
    On doit pouvoir faire une fonction pour ça, non?
    Un truc du genre:
    Code C++ :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    std::string wstr_to_u8(std::wstring uneWString)
    {
    	return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(uneWString);
    }
    Marche pas : from_bytes : erreur : ???
    Etc...

    Plus tard...

    Merci à tous...

  10. #190
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut
    Bonsoir Bacelar,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    const std::vector<std::wstring> lire_fichierTxt(std::wstring const& nomFichier, std::vector<std::wstring> separeteurs)
    {
    ...
        bool found = false;
    
        std::wstring separeteur = separeteurs[0]; // Moi, pas de solition !!!
    
        do
        {
            found = false;
            size_t pos_found = std::string::npos;
            std::wstring sep_found = "";
    
            for( auto&& sep : separateurs)
            {
                std::size_t pos = converti.find(separeteur);
                if(pos != std::wstring::npos && (!found || pos_found > pos))
                {
                    pos_found = pos;
                    found = true;
                    sep_found = sep;
                }
            }
    
            if(found)
            {
                retVal.push_back(converti.substr(0, pos_found));
                converti = converti.substr(pos_found + sep_found.length());
            }
        }while(found)
    
        if(converti.length()>0)
        {
            retVal.push_back(converti);
        }
    }
    ===>

    Merci d'avance

  11. #191
    Expert éminent sénior
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 068
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 068
    Points : 12 111
    Points
    12 111
    Par défaut
    Marche pas !!!
    Messages d'erreur SVP.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    std::wstring separeteur = separeteurs[0]; // Moi, pas de solition !!!
    Pourquoi utiliser "separeteur" et pas "sep" à la ligne 16 ?

  12. #192
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
                std::size_t pos = converti.find(separeteur);
    Ok ou pas ?

    Merci

  13. #193
    Expert éminent sénior
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 068
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 068
    Points : 12 111
    Points
    12 111
    Par défaut
    Bin non, si on a passé une liste (std::vector) en paramètre, c'est pour qu'elle serve.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    std::size_t pos = converti.find(sep);

  14. #194
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut
    Bonjour,

    Ok !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    const std::vector<std::wstring> lire_fichierTxt(std::wstring const& nomFichier, std::vector<std::wstring> separeteurs)
    {
    ...
        bool found = false;
     
        //std::wstring separeteur = separeteurs[0]; // Moi, pas de solition !!!
     
        do
        {
            found = false;
            size_t pos_found = std::string::npos;
            std::wstring sep_found = L"";
     
            for (auto&& sep : separeteurs)
            {
                std::size_t pos = converti.find(sep);
                if (pos != std::wstring::npos && (!found || pos_found > pos))
                {
                    pos_found = pos;
                    found = true;
                    sep_found = sep;
                }
            }
     
            if (found)
            {
                retVal.push_back(converti.substr(0, pos_found));
                converti = converti.substr(pos_found + sep_found.length());
            }
        } while (found);
     
        if (converti.length() > 0)
        {
            retVal.push_back(converti);
        }
        return retVal;
    }
    Mais, si :
    Créée par.txt
    ----------------------
    Christina Applegate
    Linda Cardellini, James Marsden
    Pas grave !!! ok !

    Mais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    throw std::runtime_error("Le fichier '" + wstr_to_u8(nomFichier) + "' est vide.");
    Pas compris !!! Macro et/ou wstr_to_u8 ? Exemple ?

    Merci beaucoup

  15. #195
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut
    Heu, pardon !

    Créée par.txt
    ----------------
    Alfred Gough, Miles Millar
    et
    Créée par.txt
    ----------------
    Jan Holoubek
    Bartlomiej Ignaciuk
    ???

    Merci d'avance

  16. #196
    Expert éminent sénior
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 068
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 068
    Points : 12 111
    Points
    12 111
    Par défaut
    Citation Envoyé par Laurent_B_ Voir le message
    Bonjour,

    Mais, si :
    Créée par.txt
    ----------------------
    Christina Applegate
    Linda Cardellini, James Marsden
    Pas grave !!! ok !
    En utilisant un std::vector en type de paramètre, vous pouvez avoir plusieurs séparateurs différents.
    Ici, juste avec 2 séparateurs, vous gérez aussi bien
    Créée par.txt
    ----------------------
    Christina Applegate
    Linda Cardellini, James Marsden
    que
    Créée par.txt
    ----------------------
    Christina Applegate
    Linda Cardellini
    James Marsden
    que
    Créée par.txt
    ----------------------
    Christina Applegate, Linda Cardellini, James Marsden
    etc...

    Faut juste appeler la fonction "lire_fichierTxt" avec les bonnes valeurs de paramètre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    std::vector<std::wstring> liste_a_afficher = lire_fichierTxt(nomFichier, {L"\n",L", "});
    {L"\n",L", "}, c'est un std::vector initialisé avec 2 items :
    L"\n"
    L", "

    Ainsi, le retour à la ligne et la "virgule + espace" seront des séparateurs entre les noms des personnes.

    Citation Envoyé par Laurent_B_ Voir le message
    Mais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    throw std::runtime_error("Le fichier '" + wstr_to_u8(nomFichier) + "' est vide.");
    Pas compris !!! Macro et/ou wstr_to_u8 ? Exemple ?

    Merci beaucoup
    Pas besoin de MACRO, c'est une sale habitude que j'ai d'utiliser les MACRO pour la gestion des erreurs.
    La fonction "wstr_to_u8" proposée par @Médinoc fera très bien l'affaire, et bien plus "type-safe" qu'une MACRO.

    Citation Envoyé par Laurent_B_ Voir le message
    Heu, pardon !
    ...
    En passant {L"\n",L", "} comme 2ème paramètre de lire_fichierTxt, ça prend aussi ces cas de figure.

  17. #197
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    En utilisant un std::vector en type de paramètre, vous pouvez avoir plusieurs séparateurs différents.
    ...
    Merci beaucoup
    Merci beaucoup

    Pas besoin de MACRO, c'est une sale habitude que j'ai d'utiliser les MACRO pour la gestion des erreurs.
    La fonction "wstr_to_u8" proposée par @Médinoc fera très bien l'affaire, et bien plus "type-safe" qu'une MACRO.
    et :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    std::string wstr_to_u8(std::wstring uneWString)
    {
        return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(uneWString);
    }
    Marche pas !!!
    ???

  18. #198
    Expert éminent sénior
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2005
    Messages
    5 068
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2005
    Messages : 5 068
    Points : 12 111
    Points
    12 111
    Par défaut
    Marche pas !!!
    Message d'erreur, SVP.

  19. #199
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut
    Nom : Capture.PNG
Affichages : 153
Taille : 15,8 Ko

  20. #200
    Nouveau Candidat au Club Avatar de Laurent_B_
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2021
    Messages
    379
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 379
    Points : 0
    Points
    0
    Par défaut
    Bonjour,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    std::string wstr_to_u8(std::wstring uneWString)
    {
        return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(uneWString);
    }
    ???

    -----------------------------------

    Exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    void afficher_Genre(std::wstring& genre_filename, std::wstring const& nomFichier, std::vector<std::wstring>& genres_renvoyes, const std::vector<std::wstring>& genres_valides)
    { // Genre
        std::size_t pos_txt = genre_filename.find(L".txt");
        assert((pos_txt != std::wstring::npos) && L"Erreur !!!");
        std::wstring radical = genre_filename.substr(0, pos_txt);
        std::vector<std::wstring>g;
        g = lire_fichierTxt(nomFichier, { L"\n", L", " });
        for (auto&& genre : g)
        {
            if (std::find(genres_valides.begin(), genres_valides.end(), genre) != genres_valides.end())
                genres_renvoyes.push_back(genre);
            else
            {
                assert((false) && "Attention genre non valide !!!");
            }
        }
    // Ici :
        if(...)
            E.afficher_X(-1, genres_renvoyes, L"Pas de genre…");
    
    }
    Oui ou non ???

    Pour :
    Nom : Capture d’écran 2022-11-30 165451.png
Affichages : 141
Taille : 5,6 Ko

    Merci à tous

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Probléme avc la formclosing
    Par dv-2008 dans le forum VB.NET
    Réponses: 2
    Dernier message: 23/03/2008, 16h33
  2. probléme avc console.readline()
    Par dv-2008 dans le forum VB.NET
    Réponses: 7
    Dernier message: 10/03/2008, 00h33
  3. j'ai un probléme avc un code vb.net aider moi svp
    Par dv-2008 dans le forum VB.NET
    Réponses: 12
    Dernier message: 29/01/2008, 09h20
  4. Problème avc une requête
    Par Raiga dans le forum Requêtes et SQL.
    Réponses: 3
    Dernier message: 30/06/2007, 18h36
  5. Toujours problème de lien avce la lib Cblas
    Par Kirou dans le forum Autres éditeurs
    Réponses: 1
    Dernier message: 19/06/2007, 14h50

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