String str1, str2("init2"), str3 = "init3"char s1[100], s2[100], s3[100];
cout << "\nEnter a value for str1 (no spaces): ";
cin >> s1;
str1 = s1;
cout << "\nEnter a value for str2 (no spaces): ";
cin >> s2;
str2 = s2;
cout << "\nEnter a value for str3 (no spaces): ";
cin >> s3;
str3 = s3;
cout << "\nAfter assignments..." << endl;
PrintString("str1", str1);
PrintString("str2", str2);
PrintString("str3", str3);
// Access some elements...
int i;
cout << "\nEnter which element of str1 to display: ";
cin >> i;
cout << "Element #" << i << " of str1 is '" << str1[i]
<< "'" << endl;
cout << "\nEnter which element of str2 to display: ";
cin >> i;
cout << "Element #" << i << " of str2 is '" << str2[i]
<< "'" << endl;
cout << "\nEnter which element of str3 to display: ";
cin >> i;
cout << "Element #" << i << " of str3 is '" << str3[i]
<< "'" << endl;
// Append some strings...
cout << "\nEnter a value to append to str1 (no spaces): ";
cin >> s1;
// str1.append(s1); // Actually, the cstring is converted to String object here by the constructor
str1 += s1; // same as above
cout << "\nEnter a value to append to str2 (no spaces): ";
cin >> s2;
str2 += s2;
cout << "\nEnter a value to append to str3 (no spaces): ";
cin >> s3;
str3 += s3;
On
"\nEnter a value for str1 (no spaces): ";
str1,2,3 = 1 i get error no operator "=" matches these operands operand types are : String = char[100]
On
String str1, str2("init2"), str3 = "init3"
no suitalbe constructor exist to convert from const char[6] to String
On str1,2,3 += s1,2,3
error: no operator "+=" matches these operands
operand types are: String += char[100]
I don't know what i did wrong Plz help and I have Error on
fstr += str.fstr;
1) You haven't defined an assignment operator that can set your String class to be equal to a char array. The compiler can't magically know how to do this - you need to define it.
2) Similarly, you haven't defined a constructor that can take a char array as an argument.
3) Similarly, you haven't defined a += operator that can take a char array as an operand.
4) You can't just add two char arrays like that to make a longer array. You need to use the string manipulation functions in the standard C library.