I recently learnt the cstring arrays and wanted to try out a basic operation of adding two strings together, in a normal string using as header you can add string1+string2=string3. But I tried doing this for cstrings and I get an error when I follow this format which is probably not right. Here is the code, the code is just for printing my first and last name as 1 name in a string.
#include<iostream>
#include<cstring>
using namespace std;
int main() {
char fname[100], lname[100], full_name[100];
int i, j;
i = 0;j = 0; // i is index of fname and j is index for lname
cout << "Enter your first name: ";
cin.getline(fname, 100);
cout << "Enter your last name: ";
cin.getline(lname, 100);
for (i;fname[i] != '\0';i++) {
full_name[i] = fname[i];
}
std::string(fname +" "+ lname);
cout << "i =" << i;
full_name[i] = ' ';
i = i + 1;
for (i, j;lname[j] != '\0';i++, j++) {
full_name[i] = lname[j];
}
cout << "Your full name is: " << full_name << endl;
system("pause");
return 0;
}