#char concatenation
30 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
@supple vale
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
int printATOZ(string pass) {
int counter = 0;
string word;
for (char ch = 'A'; ch <= 'Z'; ch++) {
for (char c = 'A'; c <= 'Z'; c++) {
for (char j = 'A'; j <= 'Z'; j++) {
word = ch + c + j;
cout << word << " ";
if (word == pass) {
counter++;
return counter;
}
else
counter++;
}
}
}
return counter;
}
(btw if you add cpp after ``` (and on the same line) you get syntax highlighting)
the first one
word = ch + c + j;
this does not concatenate characters
char in c++ is really just a small int
so ch + c + j is actually just adding 3 numbers together
oh
the reason word + ch concatenates is because std::string + char is overloaded to do that
but char + char is not
thanks for this information thats explain alot
the reason you get weird characters is because when these are converted back to characters they aren't in the normal ranges so its outputting whatever the character would be (and theyre strange)
is there any simple solution for this
i will try this 3 times
that would indeed work
although you have to make sure you do it correctly
since word = ch + c + j was intented to set the whole string
if you do word += ch then its concatenating to what was there before, without resetting the string