-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_characters_c++.cpp
More file actions
38 lines (36 loc) · 928 Bytes
/
String_characters_c++.cpp
File metadata and controls
38 lines (36 loc) · 928 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
33
34
35
36
37
38
🔴chuỗi trong c++
nhập tên và tuổi sinh viên
🎈code:
#include <iostream>
#include <string>
using namespace std;
int main(){
string hoten;
int tuoi;
cout << "\n nhap tuoi sinh vien: " ;
cin >> tuoi;
cin.ignore();
cout<< "\n ho ten sinh viên: ";
getline(cin,hoten);
cout << "\n ho ten sinh viên: " << hoten;
cout << "\n tuoi sinh viên: "<< tuoi;
system("pause");
return 0;
}
🔴CÁC HÀM STRING TRONG C++
#include <iostream>
#include <string>
using namespace std;
int main(){
string s ="lap trinh";
s.erase(s.begin()+3);// xoá 1 kí tự tại vt số 3
cout << "\n chuoi sau khi xoa: "<< s;
// ===
s.insert(s.begin()+ 3, 't');// hàm thêm 1 kí tự 't' tại vị trí số 3
cout << "\n chuoi sau khi them: "<< s;
cout << "\n do dai cua chuoi: "<< s.length();
//*******
s.push_back('C'); // hàm thêm 1 kí tự vào cuối chuỗi
system("pause");
return 0;
}