[問題] c++用副程式大小寫轉換

看板C_and_CPP作者 (sariel)時間12年前 (2013/12/27 01:09), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
不好意思,c++新手,指標副程式方面還不是很熟 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) C++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 如何將字串傳到副程式?並且有點看不出這錯誤是什麼意思。 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): cannot convert 'std::string' to 'char*' for argument '1' to 'char' strlwr(char*) 程式碼(Code):(請善用置底文網頁, 記得排版) #include<iostream> #include<cstdlib> using namespace std; void stringlower(string sentence); int main() { int i, x; int j = 1; int k = 0; char sentence[50000]; cout<<"請輸入要轉換的英文"<<endl; cin.getline(sentence,50000); for(i = 0; i<j; k++ ) { cout<<"如果要轉換成全部大寫,請按1"<<endl; cout<<"如果不再做另外的修改,請按5"<<endl; cin >> x; if (x == 1) stringlower(sentence); else i = 2; } system("pause"); return 0; } void stringlower(string sentence) { strlwr(sentence); cout<<"轉換大寫:"<<sentence<<endl; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 120.126.67.223

12/27 08:54, , 1F
這跟指標副程式有什麼關係?重點是你不能直接將
12/27 08:54, 1F

12/27 08:54, , 2F
char[] 轉成 string
12/27 08:54, 2F

12/27 08:55, , 3F
你兩個要一致的型態才可以
12/27 08:55, 3F

12/28 04:01, , 4F
問題應該是 strlwr 吃的是 char[] 但你給他 string
12/28 04:01, 4F
文章代碼(AID): #1Il6BKNq (C_and_CPP)