c++ ifstream with a variable filename -


i'm trying open file wich name composed constant , variable parts.

my actual code

char filename[100]; char extension1[] = ".pdb"; vector<string> id;  //code find ids(it works)  sprintf(filename, "/home/giovanni/scrivania/enzimi/ligan/%s", id[1].c_str()); sprintf(filename, "%s%s", filename,extension1); 

the problem filenames becomes

.pdbe/giovanni/scrivania/enzimi/ligan/102m

instead of

/home/giovanni/scrivania/enzimi/ligan/102m.pdb

tnx in advance

simply use std::string:

string filename = "/home/giovanni/scrivania/enzimi/ligan/" + id[1] + ".pdb";  ...  std::ifstream file(filename.c_str()); 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -