#include "iostream"\n#include "cstring"\n\nvoid copyString(const char* a, int m, char* b) {\n int len = strlen(a);\n int j = 0;\n for(int i = m-1; i < len; i++) {\n b[j] = a[i];\n j++;\n }\n b[j] = '\0';\n}\n\nint main() {\n const char* a = "Hello World";\n int m = 4;\n char b[100];\n copyString(a, m, b);\n std::cout << b << std::endl;\n return 0;\n}\n\n#include "iostream"\n#include "string"\n\nstd::string copyString(const std::string& a, int m) {\n return a.substr(m-1);\n}\n\nint main() {\n std::string a = "Hello World";\n int m = 4;\n std::string b = copyString(a, m);\n std::cout << b << std::endl;\n return 0;\n}

C++ 字符串复制:从指定位置开始截取字符串 - 使用C字符串和string类实现

原文地址: https://www.cveoy.top/t/topic/pC0h 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录