I am trying to append more strings together, when I use append once, it works fine, but after using it again it fails.
camName = "./XML//X";
std::string camera1 = "cam1";
camName.append(camera1);
This gives me string ./XML//Xcam1 and it's fine.
camName = "./XML//X";
std::string xml = ".xml";
camName.append(xml);
This also gives a good result -> ./XML//X.xml
But then I tried to do both:
camName = "./XML//X";
std::string camera1 = "cam1";
camName.append(camera1);
std::string xml = ".xml";
camName.append(xml);
I expected this to give me -> ./XML//Xcam1.xml
But instead I get something like this -> ≡┼2U_
EDIT: This is my whole function:
#include <string>
using std::string;
bool MyStitcher::checkCameras(string c1, string c2, string c3, string c4, string c5, string c6) {
string camName = "./XML//X";
if (c1 != "a") {
camName.append(c1);
}
else if (c2 != "a") {
camName.append(c2);
}
else if (c3 != "a") {
camName.append(c3);
}
else if (c4 != "a") {
camName.append(c4);
}
else if (c5 != "a") {
camName.append(c5);
}
else if (c6 != "a") {
camName.append(c6);
}
std::string xml = ".xml";
camName.append(xml);
printf("name %s\n", camName);
if (FILE *file = fopen(camName.c_str(), "r")) {
fclose(file);
return true;
}
else {
return false;
}
}
If one of the if statements is true, i get weird result(c1,c2,... are strings like "cam1" etc.)