c++tostring
时间: 2023-10-18 14:21:11 浏览: 85
As an AI language model, I am assuming you are referring to the `toString()` method which is commonly used in programming languages to convert an object to a string representation.
In JavaScript, the `toString()` method can be used on any object to get a string representation of that object. For example:
```
let num = 123;
let str = num.toString();
console.log(str); // Output: "123"
```
In Java, the `toString()` method is used to get a string representation of an object. It is a method of the `Object` class, and can be overridden in subclasses to provide a customized string representation of the object. For example:
```
public class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
// Example usage:
Person person = new Person("John", 30);
String str = person.toString();
System.out.println(str); // Output: Person{name='John', age=30}
```
阅读全文