0
string class
the code is: https://code.sololearn.com/ca19a22A1697 problem: I want to pass a string with the size from the main function but don't know how.Can someone show me how I can do it.
5 Respostas
+ 1
Not sure what you want to do, but the implementation of String(const char*) is wrong because len is undefined. You can get the len with the following:
len = 0;
const char* p = str;
while(*p++) ++len;
You can also initialize your data in the loop and remove the memcpy() if you want.
This way, the calling of String("Text") will Initialize data and len correctly.
+ 1
You could try this as well
https://code.sololearn.com/cA10a19a13A1/?ref=app
+ 1
@Martin Thanks a trillion ...
0
The question given was:
10.6
Implement a String class. Each object of this class will represent a character string. Data
members are the length of the string and the actual character string. In addition to constructors, destructor, access functions, and a print function, include a “subscript” function.
0
@Flash Thanks a lot