Template specialization c++ | Sololearn: Learn to code for FREE!

+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; } };

c++

11/23/2021 12:19:53 PM

Brent Tyson

2 Answers

New Answer

+3

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!