在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
StdStringTrimTest.cpp #include <iostream> int main() { std::string str(" 字符串 String "); std::cout << str << std::endl; std::cout << str.size() << std::endl; str.erase(str.find_first_of(' '), str.find_first_not_of(' ')); str.erase(str.find_last_not_of(' ') + 1); std::cout << str << std::endl; std::cout << str.size() << std::endl; return 0; } CStyleStringTrimTest.c #include <stdio.h> #include <string.h> #define STRING_LENGTH 10000 int main() { const char *text = " 字符串 String "; printf("%s\n%u\n", text, strlen(text)); while (*text == ' ') ++text; char str[STRING_LENGTH]; strcpy(str, text); size_t i = strlen(str) - 1; while (str[i] == ' ') str[i--] = '\0'; printf("%s\n%u\n", str, strlen(str)); return 0; } Compilation.bat g++ -std=c++11 StdStringTrimTest.cpp -o StdStringTrimTest gcc -std=c11 CStyleStringTrimTest.c -o CStyleStringTrimTest |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论