char array to string

Hi, I have some code:

1
2
char cHomeTeamFaceOffsPercentageWon[100];
memcpy(cHomeTeamFaceOffsPercentageWon,cSqlHomeTeamFaceOffsPercentageWon,100);


After this, for example, cHomeTeamFaceOffsPercentageWon is, "29%".


Then, I use

std::string szwPercentageWon = std::string(cHomeTeamFaceOffsPercentageWon);

szwPercentageWon is then, "2". Shouldn't this convert correctly, to "29%" as well.


Or is there something I'm missing? Maybe the termination character, or something.


Thanks!


c
This works for me.

1
2
3
4
5
        char cHomeTeamFaceOffsPercentageWon[100];
        char cSqlHomeTeamFaceOffsPercentageWon[100] {'2', '9', '%'};
        memcpy(cHomeTeamFaceOffsPercentageWon, cSqlHomeTeamFaceOffsPercentageWon, 100);
        std::string szwPercentageWon(cHomeTeamFaceOffsPercentageWon);
        std::cout << szwPercentageWon<< std::endl;
Topic archived. No new replies allowed.