Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

call to undefined function 'StrToInt'

0 views
Skip to first unread message

fidodi...@bbs.mgt.ncu.edu.tw

unread,
Apr 7, 2004, 12:55:14 AM4/7/04
to
那麼請問如果要在C++裡
把string轉成Int要怎麼轉
我試過
String x;
Int y;
x = '1234';
y = int (x);
結果不行...請指教

--
◎ [1;31m龍 [32m貓 [33m資 [34m訊 [35m天 [36m地 [0m( [1mbbs.mgt.ncu.edu.tw [0m)
◎[ [1;33;46mfidodido [0m]From: 220098.D13-220.ncu.edu.tw

..

unread,
Apr 7, 2004, 5:34:59 AM4/7/04
to
※ 引述《fidodi...@bbs.mgt.ncu.edu.tw ( )》之銘言:

> 那麼請問如果要在C++裡
> 把string轉成Int要怎麼轉
> 我試過
> String x;
> Int y;
> x = '1234';
> y = int (x);
> 結果不行...請指教
可用C的函式 atoi

--
[1;32m※ Origin: [33m交大資工鳳凰城資訊站 [37m<bbs.csie.nctu.edu.tw> [m
[1;31m◆ From: [36mms1.me.nctu.edu.tw [m

人間放逐

unread,
Apr 7, 2004, 9:00:14 AM4/7/04
to
==> fidodido ( ) 提到:
: 那麼請問如果要在C++裡

: 把string轉成Int要怎麼轉
: 我試過
: String x;
: Int y;
: x = '1234';
: y = int (x);
: 結果不行...請指教

可以用C++的stringstream類別,要#include <sstream>
因為是要「輸出」到整數,所以用ostringstream oss(x);
﹝假設你已經定義string x = "1234";﹞
然後就可以用oss >> y;即可。

stringstream的詳細用法再去看看書吧,別看太舊的書,因為這種類別
好像是新加入的﹝之前有strstream類別,不過使用的彈性不大﹞。

--
◎ [1;31m龍 [32m貓 [33m資 [34m訊 [35m天 [36m地 [0m( [1mbbs.mgt.ncu.edu.tw [0m)

◎[ [1;33;46mTailss [0m]From: 218-32-98-sparc224.pchome.com.tw

0 new messages