[問題] string的用法

看板C_and_CPP作者 (小恭)時間15年前 (2009/04/12 00:11), 編輯推噓2(2011)
留言13則, 7人參與, 最新討論串1/2 (看更多)
%d=int %f=float %c=char ===>类推:%s =string 於是我寫了: #include<iostream> #include<string.h> #include<stdlib.h> #include<stdio.h> using namespace std; int main () { string a; scanf("%s",&a); printf("%s",a); system("pause"); } 10 D:\Program Files\Dev-Cpp\my work\ppppppppp.cpp [Warning] cannot pass objects of non-POD type `struct std::string' through `...'; call will abort at runtime 输入后直接跳出没有映出 我該如何修改,或者說沒有這種用法? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.123.240.55

04/12 00:15, , 1F
scanf 請用 char a[100]; 這種 c-style 的 string 吧?
04/12 00:15, 1F

04/12 00:16, , 2F
用cin cout或用c-style string
04/12 00:16, 2F

04/12 01:32, , 3F
printf 那邊要用a.c_str()
04/12 01:32, 3F

04/12 07:27, , 4F
你知道 <string> 跟 <string.h> 有什麼不同嗎?
04/12 07:27, 4F

04/12 10:42, , 5F
怎麼是簡體字@@ 但ip是中正大學
04/12 10:42, 5F

04/12 14:31, , 6F
大概是選到了bbs輸出轉簡體字吧
04/12 14:31, 6F

04/13 01:25, , 7F
回james732,我是想試試看有沒有這種寫法
04/13 01:25, 7F

04/13 01:26, , 8F
回legendmtg,我google了一下"cin cout"好像是兩個東西,
04/13 01:26, 8F

04/13 01:27, , 9F
但不清楚是甚麼,能否說明下,謝謝
04/13 01:27, 9F

04/13 01:29, , 10F
回akasan,請問是修改成printf("%s",a.c_str());這樣嗎?
04/13 01:29, 10F

04/13 01:29, , 11F
可是一樣不能執行(可以編譯)
04/13 01:29, 11F

04/13 01:32, , 12F
回tinlans,我不知道的說,有<string>這種標頭檔?
04/13 01:32, 12F

04/13 01:32, , 13F
麻煩說明下
04/13 01:32, 13F
文章代碼(AID): #19uC4Os3 (C_and_CPP)
文章代碼(AID): #19uC4Os3 (C_and_CPP)