is there a toString() method in c just like in C#?
v=k.toString();
is there a toString() method in c just like in C#?
v=k.toString();
First ask yourself if there are classes in C. Then when you realize there aren't, ask yourself why the heck you asked such a silly question in the first place.
No strings in C (outside of char arrays), no classes, no OOP (unless you simulate it with function pointers, etc.).... What are you even trying to do and why are you asking this?
chill... typo...its c++...i know there arent any classes in c
Typo? Mmkay, then this should be in the C++ section.
And no, there is no standard toString() function/method in C++. It's usually done via operator overloading.... ie. << operator for std::cout.
Moved.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
try std::stringstream
Templates templates templates.
This function will convert ANY type of object to a string, provided that the appropriate ostream insertion operator is defined. To convert custom objects, you merely write a function:Code:template <typename T> std::string toString(const T &val_p) { std::stringstream x; x << val_p; return x.str(); }
This function will automatically be used by the toString() function.Code:std::ostream &operator<<(std::ostream &stream_p, const my_class &val_p) { // ... return stream_p; }