substr(0, end) << endl; s.erase(s.begin(), s.begin() + end + 1); end = s.find(del); } cout << s.substr(0, end); } int main() { string a = "I love to read articles on Favtutor."; // Here, the delimiter is white space. string del = " "; find_str(a, del...
basic_string &replace( iterator start, iterator end, const char *str, size_type num ); basic_string &replace( iterator start, iterator end, size_type num, char ch ); replace()函数: 用str中的num个字符替换本字符串中的字符,从index开始用str中的num2个字符(从index2开始)替换本字符串中的字符...
string s3(s2); // 作用同上 string s4 = "hello world"; // 用 "hello world" 初始化 s4,除了最后的空字符外其他都拷贝到s4中 string s5("hello world"); // 作用同上 string s6(6,'a'); // 初始化s6为:aaaaaa string s7(s6, 3); // s7 是从 s6 的下标 3 开始的字符拷贝 string s8(s...
int strcmp(const char *string1, const char *string2); 比较字符串string1和string2大小. 返回值< 0, 表示string1小于string2; 返回值为0, 表示string1等于string2; 返回值> 0, 表示string1大于string2. int stricmp(const char *string1, const char *string2); 比较字符串string1和string2大小,和strc...
substr(pos1)); } // 删除左右两边空格 void Del_Trim(std::string& s) { if (s.empty()) { return; } s.erase(0, s.find_first_not_of(" ")); s.erase(s.find_last_not_of(" ") + 1); } // 删除所有空格 void Del_Space(std::string& res) { int r = res.find('\r\n');...
1、substr函数格式 (俗称:字符截取函数) 格式1: substr(string string, int a, int b); 格式2:substr(string string, int a) ; 解析: 格式1: 1、string 需要截取的字符串 2、a 截取字符串的开始位置(注:当a等于0或1时,都是从第一位开始截取) ...
#include <string> int main() { std::string line; // empty string while(std::getline(std::cin, line)) { // read line at time until end-of-file std::cout << line << std::endl; // write s to the output } return 0;
#include <string> int main() { std::string line; // empty string while(std::getline(std::cin, line)) { 1. 2. 3. 4. 5. 6. 7. // read line at time until end-of-file std::cout << line << std::endl; // write s to the output ...
if (start == std::string::npos) break; // over end = str.find_first_of(delimiter, start + 1); if (end == std::string::npos) { foreach_function(num, str.substr(start)); break; } foreach_function(num, str.substr(start, end - start)); ...
C-String, SubStr, and Strtok So, this might be the most confusing part of C++ for me thus far. Even having my friend show me a code for supposedly SubStr and Strtok has me dumbfounded (See his example code below) from what i understand it removes the spaces and any/all punctuation. ...