I vaguely recall some way to temporarily concatenate arrays of the same type and was wondering if anyone knew either the syntax, of if I was imagining things...
int myFunction(char *buffer){
printf("%s", buffer);
}
int main(){
char array1[10];
sprintf(array1, "hello");
char array2[10];
sprintf(array1, "world");
myFunction(array1 + " " + array2);
// or maybe
myFunction(array1" "array2);
// or maybe
myFunction(array1." ".array2);
}
Obviously this wont compile and is syntactically wrong but I thought there might be something similar that would work as intended. Maybe all that PHP and Javascript I learned a few years ago is infecting my mind :P
In my head it I think it could never work unless the array addresses were sequential however I just wanted to know for sure :)
Thanks Duoas, it helped me as well in understanding the string concatenate .
I added few lines in your code to make it more easy for my comprehension.
With thanks for Duoas , I am appending / repeating his code here with slight additions:
using namespace std;
int main() {
string greeting_part_1 = "Hello";
string name ;
char *myAge;
int age ;
cout<< " Please write your name ";
cin>> name;
cout<< " What is your age ? ";
cin>> age;
// use itoa (IntegerToAlpha) to convert to string equivalent
itoa( age, myAge, 10 ); // the 10 is the number base
// myAge = String(age);
cout << (greeting_part_1 + " world!") << endl; // Again, the result is the concatenated string
cout << greeting_part_1 << endl; // but this time, the source string was not modified
string greeting = greeting_part_1 + " " + name + " you are in this world! for " + myAge + " years " ;
cout << greeting << endl;
system("pause");
return 0;
}