C++: string operator overload

后端 未结 3 1206
生来不讨喜
生来不讨喜 2021-01-21 14:00

Can I overload existing function/operator in existing class?

I was trying to do:

#include 
#include 
using namespace std;

         


        
3条回答
  •  温柔的废话
    2021-01-21 14:12

    Use

    std::ostringstream

    #include 
    #include 
    
    using namespace std;
    
    int main()
    {
        std::ostringstream ss;
        ss << "Hello" << " " << "world";
    
        std::string s = ss.str(); 
        ss.str(std::string()); 
    
        cout << s << endl;
        return 0;
    }
    

    https://onlinegdb.com/rkanzeniI

提交回复
热议问题