S
S
Sergey Ivchenko2015-11-27 22:45:42
C++ / C#
Sergey Ivchenko, 2015-11-27 22:45:42

Are there ready-made solutions in C++ for implementing the toString method?

Actually, the whole question is in the title: is there a tool in C ++ that allows you to perform something similar to toString on class objects?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg Tsilyurik, 2015-11-27
@Serg89

What you call toString is, in C++ terminology , a type conversion operator to a string representation.
For your class X, you describe:
or (with certain difficulties):
And then in the code you use:
cout << X;

T
Therapyx, 2015-11-27
@Therapyx

#include <string>
....
to_string(); есть уже с с++11.

Or are you talking about something else? ))

G
GavriKos, 2015-11-27
@GavriKos

There is. It's called OOP. You inherit all classes from the Object base class, you overload ToString for all of them, and then return what you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question