Code:
int main() {
string s1 = "", song = "blablabla.mp3", outputsong( song, 0, song.length()-4 );
int j = 0, i = 0;
while(song[j++]!='.');
while(song[j]) {
s1[i++] = song[j++];
}
if(s1=="mp3") { //Please, check this line!!!!
outputsong += ".ogg";
}
else if(s1=="ogg") {
outputsong += ".mp3";
}
else {
}
cout << song << endl << outputsong << endl;
return 0;
}
What make me confuse is the output of the program is:
blablabla.mp3
blablabla
What I expected from this program is:
blablabla.mp3
blablabla.ogg
When I check this program with gdb:
After this statement executed:
Code:
while(song[j]) {
s1[i++] = song[j++];
}
(gdb) p s1
$18 = {static npos = 4294967295,
_M_dataplus = {<allocator<char>> = {<No data fields>},
_M_p = 0x804a4bc "mp3"}, static _S_empty_rep_storage = {0, 0, 1, 0}}
But why if(s1=="mp3") statement does not give true condition????