作者hhashoww (在淡江第六年的日子...)
看板C_and_CPP
标题Re: [问题] string的用法
时间Sun Apr 12 00:18:53 2009
#include<stdio.h>
using namespace std;
int main ()
{
char a[100] //好像没有内建string这种型态的格式
scanf("%s",a);
/*
或用<string.h>内的写法
gets(string);
*/
printf("%s",a);
system("pause");
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.133.138.13
1F:→ sunneo:如果没有stl、没有string, 那namespace存在的可能性 ? 04/12 01:10
2F:→ fasthall:不是没有内建 是他没有include 04/12 01:23
3F:→ JohnyDamon:没有内建没错 C语言中并无字串资料型别(String) 04/12 04:06
4F:推 carlcarl:他的写法不是c++吗 不然怎会有iostream? 04/12 06:32
5F:→ fasthall:他是用C++不是用C 04/12 10:13
6F:→ fasthall:呃不过那也不叫内建啦 我用词错误 04/12 10:14
7F:推 world9918:我记得string是C++的标准类别 string.h是C的函式库? 04/12 11:49
8F:推 fasthall:C++要#include<string> 然後string在std里面 04/12 14:39
9F:→ discipile:在此先跟各位抱歉下,我没有事先说是哪款编译器 04/13 01:34
10F:→ discipile:我是用dev c++ 4.9.9.2 04/13 01:34
11F:→ discipile:回fasthall,我看的不是很懂,能否说明下 04/13 01:39
12F:→ discipile:如果是加入#include<string>,我加了後 04/13 01:40
13F:推 fasthall:你用string是C++的东西 不过你应该只碰过C 04/13 01:40
14F:→ discipile:能输出字串的第一个单字(ex:apple),但空格後的不能输出 04/13 01:41
15F:→ fasthall:直接用char a[length]宣告 04/13 01:41
16F:→ discipile:我们好像就是教c,但我们用的每款编译器都是c++的 04/13 01:42
17F:→ discipile:我记得有人告诉我可以用string a;这种用法 04/13 01:42
18F:→ discipile:我作业是用char a[100]这种用法,但我想试试 04/13 01:43
19F:推 fasthall:不要管这种用法 以後学C++再研究吧 然後DEV也能编译C语言 04/13 01:43
20F:→ discipile:之前别人说的用法,结果一直试不出来 04/13 01:43
21F:→ discipile:好的,到时再研究,谢谢各位的参与了! 04/13 01:45