How to combine strings?

Ok, so problem as following: Program will read disk letter from file and the create path to another file depending on that input (e.g. if input is C it shall be C:\\Someplace\\Data\\file.dat and if D - D:\\Someplace\\Data\\file.dat).
How to link this input and constant string being latter adress?
Thanks in advance :)
Last edited on
Last edited on
Are you using C++ strings or C strings?

for C++ strings:
1
2
3
string input, other = "\\Someplace\\Data\\file.dat", result;
cin >> input;
result = input+other;


for C strings:
1
2
3
4
char *input= new char[/*here the maximum length for the input string*/], *other="\\Someplace\\Data\\file.dat", *result;
cin >> input;
result = new char[strlen(input)+strlen(other)];
sprintf(result,"%s%s",input,other);
Last edited on
Topic archived. No new replies allowed.