-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_string.cpp
More file actions
52 lines (46 loc) · 1.32 KB
/
test_string.cpp
File metadata and controls
52 lines (46 loc) · 1.32 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* =====================================================================================
*
* Filename: test_string.cpp
*
* Description: ylj
*
* Version: 1.0
* Created: 08/23/2011 10:03:18 AM
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Company:
*
* =====================================================================================
*/
#include<iostream>
int main()
{
std::string str_1="1234567";
std::string str_2;
std::cout<<"***********assign=(erase)*******************"<<std::endl;
std::cout<<str_1<<std::endl;
str_2.assign(str_1,1,2);
std::cout<<str_2<<std::endl;
str_2.assign(str_1,1,std::string::npos);
std::cout<<str_2<<std::endl;
str_2.assign(str_1,1,8);
std::cout<<str_2<<std::endl;
str_2.assign("helloword",1,8);
std::cout<<str_2<<std::endl;
std::cout<<"***********assign=(erase)*******************"<<std::endl;
std::cout<<str_1<<std::endl;
str_1.assign(str_1,1,std::string::npos);
std::cout<<str_1<<std::endl;
str_1.assign(str_1,1,std::string::npos);
std::cout<<str_1<<std::endl;
str_1.assign(str_1,1,std::string::npos);
std::cout<<str_1<<std::endl;
std::cout<<"***********insert*****************"<<std::endl;
str_1.insert(0,2,'8');
std::cout<<str_1<<std::endl;
str_1.insert(0,"99");
std::cout<<str_1<<std::endl;
}