标签:new margin 第一个字符 repos ber different pre hit garbage
本文转载自http://blog.csdn.net/youxin2012/article/details/9162415
1 #include <iostream> // std::cout 2 #include <string> // std::string 3 4 int main () 5 { 6 std::string str ("There are two needles in this haystack with needles."); 7 std::string str2 ("needle"); 8 9 // different member versions of find in the same order as above: 10 std::size_t found = str.find(str2); 11 if (found!=std::string::npos) 12 std::cout << "first ‘needle‘ found at: " << found << ‘\n‘; 13 14 found=str.find("needles are small",found+1,6); 15 if (found!=std::string::npos) 16 std::cout << "second ‘needle‘ found at: " << found << ‘\n‘; 17 18 found=str.find("haystack"); 19 if (found!=std::string::npos) 20 std::cout << "‘haystack‘ also found at: " << found << ‘\n‘; 21 22 found=str.find(‘.‘); 23 if (found!=std::string::npos) 24 std::cout << "Period found at: " << found << ‘\n‘; 25 26 // let‘s replace the first needle: 27 str.replace(str.find(str2),str2.length(),"preposition"); //replace 用法 28 std::cout << str << ‘\n‘; 29 30 return 0; 31 }
其他同理
标签:new margin 第一个字符 repos ber different pre hit garbage
原文地址:http://www.cnblogs.com/cynthia-dcg/p/6178650.html