+ 1
Template specialization c++
https://sololearn.com/coach/889/?ref=app Iâm having issues with this code. Can anyone help me ? Itâs much appreciated. What I posted is the snippet I needed to produce but Iâm not getting the right answers for test results. Please refer to the link posted for the full question. //your code goes here template < > class Div < string > { public: Div (string a, string b) { cout << sizeof(a) / sizeof(b) << endl; } };
2 Answers
+ 2
Use the size() or length() member function of the std::string class to get the length of the string, i.e.
cout << a.size() / b.size() << endl;
sizeof() returns the size of the class, not the length of the string managed by an object.
+ 1
Shadow thanks so much ! I just facepalmed myself; I Forgot to use dot notation. Much appreciated!