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