#char concatenation

30 messages · Page 1 of 1 (latest)

supple vale
#

i have unexpected result here

halcyon axleBOT
#

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

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

supple vale
#
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;
}
scarlet cedar
#

(btw if you add cpp after ``` (and on the same line) you get syntax highlighting)

#

the first one

supple vale
#

ok thanks

#

this is the output

#

why its not from AAA to ZZZ

scarlet cedar
#

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

supple vale
#

oh

scarlet cedar
#

the reason word + ch concatenates is because std::string + char is overloaded to do that

#

but char + char is not

supple vale
#

thanks for this information thats explain alot

scarlet cedar
supple vale
#

is there any simple solution for this

scarlet cedar
#

yes many

#

but see if you can figure something out first :P

scarlet cedar
#

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

supple vale
#

thanks its worked

#

1solved

#

!solved