jeudi 9 septembre 2021

C++, i use the function at() from Vector, but i have problem

at problem in vector

cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char> >, std::__cxx11::basic_string<char> >::value_type' {aka 'std::__cxx11::basic_string<char>'} to 'const char*'gcc

sincerely i don't know why and how to correct this.

#include <stdio.h>
#include <conio.h>
#include <string>
#include <vector>

namespace anas 
{  
    void passwordGenerator() 
    {
        std::vector<std::string> PasswordString;

        std::string ElencoAlfabeto("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
        char CharAlfabeto[ElencoAlfabeto.length()];

        for (int Lettere_Create = 0; Lettere_Create < 8; Lettere_Create++)  
        {
            int             NumeroCarattere     = rand() % sizeof(CharAlfabeto);
            CharAlfabeto   [NumeroCarattere]    = ElencoAlfabeto[NumeroCarattere];
            
            PasswordString.push_back(CharAlfabeto[NumeroCarattere]); 
        }

        for (int Lettere_Scritte = 0; Lettere_Scritte < 8; Lettere_Scritte++)
        {
            printf (   PasswordString.at(Lettere_Scritte)    );
        }
    }
}

int main()
{
    system("cls");
    std ::printf("the program is started... \n \n");
    anas::passwordGenerator();
}

the output should be a random 8 letter generator.


yes, this is my first time using vector ... here the article i use:vector article doc

when i put the mouse-cursor on the at , i see 1 overload, what is mean overload? overload error at

Aucun commentaire:

Enregistrer un commentaire