-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
32 lines (25 loc) · 993 Bytes
/
Copy pathtest.cpp
File metadata and controls
32 lines (25 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// string::find
#include <iostream> // std::cout
#include <string> // std::string
int main ()
{
std::string str ("長いタイトルの中に、ニュースが入っているとします");
std::string str2 ("ニュース");
// different member versions of find in the same order as above:
std::size_t found = str.find(str2);
if (found!=std::string::npos)
std::cout << "first 'needle' found at: " << found << '\n';
//found=str.find("needles are small",found+1,6);
//if (found!=std::string::npos)
// std::cout << "second 'needle' found at: " << found << '\n';
//found=str.find("haystack");
//if (found!=std::string::npos)
// std::cout << "'haystack' also found at: " << found << '\n';
//found=str.find('.');
//if (found!=std::string::npos)
// std::cout << "Period found at: " << found << '\n';
//// let's replace the first needle:
//str.replace(str.find(str2),str2.length(),"preposition");
//std::cout << str << '\n';
return 0;
}