Psl/stl string
รุ่นแก้ไขเมื่อ 22:06, 11 กุมภาพันธ์ 2561 โดย Jittat (คุย | มีส่วนร่วม) (หน้าที่ถูกสร้างด้วย '== ตัวอย่าง 1 == <syntaxhighlight lang="cpp"> #include <iostream> using namespace std; main() { string s; cin >>...')
ตัวอย่าง 1
<syntaxhighlight lang="cpp">
- include <iostream>
using namespace std;
main() {
string s; cin >> s; cout << s << endl;
} <syntaxhighlight>
ตัวอย่าง 2
รับข้อมูลนำเข้าในรูปแบบ
i string1 i string2 ... x
(i เพิ่ม, x จบการทำงาน) แล้วพิมพ์รายการของ string ที่ได้รับออกมา
<syntaxhighlight lang="cpp">
- include <iostream>
- include <list>
using namespace std;
main() {
string c; string s; list<string> stlist;
while(true) {
cin >> c;
if(c.compare("i") == 0) {
cin >> s;
stlist.push_back(s);
}
if(c.compare("x") == 0) {
break;
}
}
for(auto i = stlist.begin(); i != stlist.end(); i++) {
cout << *i << endl;
}
} <syntaxhighlight>