Hi,
as in the listing, the string cant be printed normally whenever I passed a string through argv[] to label1 or label2.
but the case3 succeed. How to pass stored string or TString into Form() ?
int main( int argc, char* argv[] ){
TString label1 = Form("_%s",argv[1]); // this failed
std::string label2 = argv[1]; // this failed
TString ResultsName("");
ResultsName.Form("results/TrainingResult%s.root",label1);
std::cout << ResultsName << std::endl;
// case 3: worked
TString s("a=");
s.Form("This is %s string w/ a %d and a %f", "a", 5, 3.14);
std::cout << s << std::endl;
#include <iostream>
#include "TChain.h"
#include "TFile.h"
#include "TTree.h"
#include "TString.h"
#include "TObjString.h"
#include "TSystem.h"
#include "TROOT.h"
#include "TMVA/Factory.h"
#include "TMVA/DataLoader.h"
#include "TMVA/Tools.h"
#include "TMVA/TMVAGui.h"
int main( int argc, char* argv[] ){
TString label1 = Form("_%s",argv[1]); // this failed
std::string label2 = argv[1]; // this failed
TString ResultsName("");
ResultsName.Form("results/TrainingResult%s.root",label1);
std::cout << ResultsName << std::endl;
// case 3: worked
TString s("a=");
s.Form("This is %s string w/ a %d and a %f", "a", 5, 3.14);
std::cout << s << std::endl;
}
FYI, i am currently working on codes involving string and TSTrings. i removed the part from TMVA training (which I adapted from the example Classification.C), now i am working to take external args into parameters that go into the TMVA training
You should have got an explicit note (from the compiler) in the form: main.cxx:23:50: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘TString’ [-Wformat=]
So, it’s clear you need “label1.Data()” there.