作者discipile (小恭)
看板C_and_CPP
標題[問題] string的用法
時間Sun Apr 12 00:11:03 2009
%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
1F:→ james732:scanf 請用 char a[100]; 這種 c-style 的 string 吧? 04/12 00:15
2F:推 legendmtg:用cin cout或用c-style string 04/12 00:16
3F:→ akasan:printf 那邊要用a.c_str() 04/12 01:32
4F:→ tinlans:你知道 <string> 跟 <string.h> 有什麼不同嗎? 04/12 07:27
5F:推 stonehomelaa:怎麼是簡體字@@ 但ip是中正大學 04/12 10:42
6F:→ sunneo:大概是選到了bbs輸出轉簡體字吧 04/12 14:31
7F:→ discipile:回james732,我是想試試看有沒有這種寫法 04/13 01:25
8F:→ discipile:回legendmtg,我google了一下"cin cout"好像是兩個東西, 04/13 01:26
9F:→ discipile:但不清楚是甚麼,能否說明下,謝謝 04/13 01:27
10F:→ discipile:回akasan,請問是修改成printf("%s",a.c_str());這樣嗎? 04/13 01:29
11F:→ discipile:可是一樣不能執行(可以編譯) 04/13 01:29
12F:→ discipile:回tinlans,我不知道的說,有<string>這種標頭檔? 04/13 01:32
13F:→ discipile:麻煩說明下 04/13 01:32