標題:
2024/12/7冠毅
[打印本頁]
作者:
郭竑志
時間:
2024-12-7 13:30
標題:
2024/12/7冠毅
本帖最後由 郭竑志 於 2024-12-14 13:42 編輯
[作業檢察]
字串處理 (四) - 字串中第n個字母為何
[課堂重點]
字串處理 (六) - 取得字串長度 1
字串處理 (七) - 取得字串長度 2
字串處理 (八) - 將字串轉換為ASCII碼
stringstream 字串串流 (一)
stringstream 字串串流 (二)
[今日作業]
字串處理 (九) - 將ASCII碼轉換為字串
字串處理 (十) - 判斷大小寫
stringstream 字串串流 (三)
作者:
劉冠毅
時間:
2024-12-7 14:26
#include<iostream>
#include<cstdlib>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
char str[50];
cout<<"輸入字串: ";
cin.getline(str,50);
int sum=strlen(str);
cout<<"此字串有 "<<sum<<"個字元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2024-12-7 14:26
#include<iostream>
#include<cstdlib>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
string str;
cout<<"輸入字串: ";
getline(cin,str);
cout<<"此字串有 "<<str.length()<<"個字元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2024-12-7 14:27
#include<iostream>
#include<cstdlib>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
int sum=0;
char str[50];
cout<<"輸入字串: ";
cin.getline(str,50);
for(int i =0;str[i]!='\0';i++){
sum=sum+1;
}
cout<<"此字串有 "<<sum<<"個字元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2024-12-7 14:42
#include<iostream>
#include<cstdlib>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
string str;
cout<<"輸入字串: ";
getline(cin,str);
for(int i=0;i<str.size();i++){
cout<<int(str[i])<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2024-12-7 14:44
#include<iostream>
#include<cstdlib>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
char str[50];
cout<<"輸入字串: ";
cin.getline(str,50);
for(int i=0;i<strlen(str);i++){
cout<<int(str[i])<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
劉冠毅
時間:
2024-12-14 14:13
#include<iostream>
#include<cstdlib>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
int n;
string str="Hello world!";
cout<<str<<endl;
cout<<"字元 'l' 的索引位置 (由前往後查找): "<<str.find('l',4)<<endl;
cout<<"字元 'e' 的索引位置 (由後往前查找): "<<str.rfind('e')<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://www.istak.org.tw/seed/)
Powered by Discuz! 7.2