Aug 5, 2014 at 7:51pm UTC
std::string mystring = yourFunction();
Aug 5, 2014 at 7:58pm UTC
Cheers but I had already tried that and it didn't work. It said 'invalid conversion from 'char' to 'const char'
Aug 5, 2014 at 8:10pm UTC
Could post the function definition? That's really the only important part.
EDIT:
Oh wait, this is weird.
alphanum
and
stringLength
are globals. I see what's going on now.
std::string mystring = genRandom();
should work...
std::string::operator =
takes a char,
genRandom()
is returning a char. Can you post the code you did that failed?
Also,
Should alphanum be defined as:
1 2 3 4 5 6
static const char * alphanum[] =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"!£$%^&*()_+=-{}[]@:;#~?/>.<,\|`¬" ;
Last edited on Aug 5, 2014 at 8:18pm UTC
Aug 5, 2014 at 8:28pm UTC
Why the C-string? Why not a std::string?
1 2 3 4 5 6
static const std::string alphanum =
"0123456789"
"!@#$%^&*"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"!£$%^&*()_+=-{}[]@:;#~?/>.<,\\|`¬" ; // Don't forget to escape the escape character.
Then there would be no need for the stringLength variable since a std::string knows it's own size.
Should alphanum be defined as:
No, this is a single C-string, not an array of C-strings.
Last edited on Aug 5, 2014 at 8:37pm UTC