+ 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 Respostas
+ 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!