作者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