const CString&

// TODO: 在此处为本机数据添加绘制代码
CRect rect;
GetClientRect(rect);
CString str ("helloworld");
const CString& aa = str;


pDC->DrawText(aa, &rect, DT_CENTER);
#include <iostream> #include <cstring> using namespace std; class CSTRING { public: CSTRING() : ptr(nullptr), len(0) {} CSTRING(const char* str) { len = strlen(str); ptr = new char[len + 1]; strcpy(ptr, str); } CSTRING(const CSTRING& other) { len = other.len; ptr = new char[len + 1]; strcpy(ptr, other.ptr); } ~CSTRING() { if (ptr != nullptr) { delete[] ptr; ptr = nullptr; } } CSTRING& operator=(const CSTRING& rhs) { if (this != &rhs) { if (ptr != nullptr) { delete[] ptr; } len = rhs.len; ptr = new char[len + 1]; strcpy(ptr, rhs.ptr); } return *this; } CSTRING operator+(const CSTRING& rhs) const { CSTRING result; result.len = len + rhs.len; result.ptr = new char[result.len + 1]; strcpy(result.ptr, ptr); strcat(result.ptr, rhs.ptr); return result; } CSTRING& operator+=(const CSTRING& rhs) { len += rhs.len; char* temp = new char[len + 1]; strcpy(temp, ptr); strcat(temp, rhs.ptr); delete[] ptr; ptr = temp; return *this; } char& operator[](int index) { return ptr[index]; } void insert(const char* str, int pos) { int str_len = strlen(str); char* temp = new char[len + str_len + 1]; strncpy(temp, ptr, pos); strcpy(temp + pos, str); strcpy(temp + pos + str_len, ptr + pos); delete[] ptr; ptr = temp; len += str_len; } bool operator>(const CSTRING& rhs) const { return strcmp(ptr, rhs.ptr) > 0; } friend ostream& operator<<(ostream& os, const CSTRING& str); friend istream& operator>>(istream& in, const CSTRING& str); private: char* ptr; int len; }; ostream& operator<<(ostream& os, const CSTRING& str) { os <<"--"<<str.ptr; return os; } istream& operator>>(istream& in, const CSTRING& str) { for (int i = 0; i < str.len ; i++) { cin>>str.ptr[i]; } return in; } int main() { int n, i, j; while (cin >> n) { CSTRING *c = new CSTRING[n + 2]; for (i = 0; i < n; i++) { cin >> c[i]; } for (i = 0; i < n - 1; i++) for (j = 0; j < n - i - 1; j++) if (c[j] > c[j + 1]) { c[n] = c[j]; c[j] = c[j + 1]; c[j + 1] = c[n]; } for (i = 0; i < n; i++) c[n + 1] += c[i]; cout << c[n + 1] << endl; delete[] c; } return 0; }帮我调整代码使其能输出--aaa--bbb--ccc
05-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值