| |

VerySource

 Forgot password?
 Register
Search
View: 2582|Reply: 11

Is there a method similar to toString, equals in java?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-23 02:00:01
| Show all posts |Read mode
Ask 3 big questions:

1. Does c ++ have toString, equals, etc.?
2. Does C ++ have an orm framework? Is there a spring framework in java?
3. Is there any serialization in the standard C ++ syntax? How to use it? What is the format for serializing to a file?
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-5-4 19:00:01
| Show all posts
C ++ is not java.
Reply

Use magic Report

0

Threads

14

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-5-5 01:30:01
| Show all posts
1,
struct object
{
virtual string toString ();
};

struct car: public object
{
virtual string toString () {return "car";}
bool operator == (const car&);
};

2,
never heard of that

3.
No, there is in MFC, you can refer to it. Standard C ++ can overload ostream << and istream >> to achieve similar functions.
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-6 02:00:02
| Show all posts
Upstairs, LZ said tostring means.
int i = 1;
i.tostring () // "1"

Every data type exists in the form of a class in java.
Just implement a method yourself!
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-7 13:30:02
| Show all posts
This can be done.
char szBuff [128] = {0};
sprintf (szBuff, "% s% n% c", "HI", 2, 'c');

int i = 1;
sprintf (szBuff, "% n", i); // "1"
This can barely achieve the same effect as java tostring!
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-9 18:00:01
| Show all posts
Write your own ostream&operater << (ostream&o, [object]&obj);

then
stringstream sstrm;
sstrm << obj;
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-10 01:15:01
| Show all posts
equals is equivalent to operator ==
The standard library does not specify the serialization format
I haven't seen the C ++ ORM framework because C ++ lacks a reflection mechanism, and it is very complicated to implement. I have tried it before, and it is really difficult to use it without the reflection mechanism, and finally gave up
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-11 17:15:01
| Show all posts
toString can be implemented with stingstream,
Or use sprintf in C,
Or other methods, such as itoa, etc.

such as:
    ostringstream os;
    os << 100 << endl;
    string str = os.str (); // Get string
    cout << str << endl;
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-11 18:30:01
| Show all posts
There are equals:

#include <string>
  bool operator == (const string&c1, const string&c2);
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-11 19:15:01
| Show all posts
#include <string>
  bool operator == (const string&c1, const string&c2);
  bool operator! = (const string&c1, const string&c2);
  bool operator <(const string&c1, const string&c2);
  bool operator> (const string&c1, const string&c2);
  bool operator <= (const string&c1, const string&c2);
  bool operator> = (const string&c1, const string&c2);
  string operator + (const string&s1, const string&s2);
  string operator + (const char * s, const string&s2);
  string operator + (char c, const string&s2);
  string operator + (const string&s1, const char * s);
  string operator + (const string&s1, char c);
  ostream&operator << (ostream&os, const string&s);
  istream&operator >> (istream&is, string&s);
  string&operator = (const string&s);
  string&operator = (const char * s);
  string&operator = (char ch);
  char&operator [] (size_type index);
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list