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

string type ???

0 views
Skip to first unread message

怒向刀叢覓小詩

unread,
Sep 13, 2000, 11:43:43 PM9/13/00
to
※ 引述《willi...@cis.nctu.edu.tw (何陋居主)》之銘言:
> ==> 在 iostre...@bbs.yuntech.edu.tw (怒向刀叢覓小 的文章中提到:
> > string 是C++標準規格(可以查一下C++ Primer)
> > 記得先#include <string.h>
> ^^
> 把 .h 拿掉


依照軟體的特性有所不同吧...

在VC++ 6.0 裡頭要拿掉dot h, 在BCB裡頭就不用了

--
-------------------------------------------------------------------------------

Analyze a little, design a little, implement a little
, and test a little Grady Booch

--
[m※ Origin: 雲林科技大學藍天使 <bbs.yuntech.edu.tw> [From: 168.95.134.15]

何陋居主

unread,
Sep 14, 2000, 3:00:00 AM9/14/00
to
==> 在 iostre...@bbs.yuntech.edu.tw (怒向刀叢覓小 的文章中提到:
> > > string 是C++標準規格(可以查一下C++ Primer)
^^^^^^^^^^^

> > > 記得先#include <string.h>
> > ^^
> > 把 .h 拿掉
>
> 依照軟體的特性有所不同吧...
> 在VC++ 6.0 裡頭要拿掉dot h, 在BCB裡頭就不用了

你在說什麼呀???

不拿掉 .h 的話, 編譯器會以為你所 #include 的是 ANSI C 的 <string.h>
這可跟 ANSI C++ 的 <string> 的 std::string 沒有關係。

哪個編譯器會聰明的把 #include <string.h> 看成是去引入 C++ 的 std::string,
請告訴我。

--
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
≡ 何陋居 ≡ 資源和時間,應該用來使「表現一流」的人進步到「登峰造極」。
一個人的精力一定要用在自己所擅長的方面。 Peter Drucker
《21世紀的管理挑戰》
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>

怒向刀叢覓小詩

unread,
Sep 14, 2000, 9:00:37 PM9/14/00
to
※ 引述《willi...@cis.nctu.edu.tw (何陋居主)》之銘言:

> 你在說什麼呀???
> 不拿掉 .h 的話, 編譯器會以為你所 #include 的是 ANSI C 的 <string.h>
> 這可跟 ANSI C++ 的 <string> 的 std::string 沒有關係。
> 哪個編譯器會聰明的把 #include <string.h> 看成是去引入 C++ 的 std::string,
> 請告訴我。

Dear 大大 :

以下這段程式碼在Borland C++ Builder 5.0 的編譯器是可執行的...

#include<string.h>
#include<iostream.h>
#include<conio.h>
#include<cstring>

// using namespace std;

int main(int argc, char* argv[])
{
string cc("hello");
cout <<cc.c_str()<<endl<<strlen(cc.c_str());
getch();

return 0;
}


至於以下這段程式在BCB5.0裡頭仍是可執行的 :

#include<string>
#include<iostream>
#include<conio>
#include<string.h>

using namespace std;

int main(int argc, char* argv[])
{
string cc("hello");
cout <<cc.c_str()<<endl<<strlen(cc.c_str());
getch();

return 0;

何陋居主

unread,
Sep 16, 2000, 3:00:00 AM9/16/00
to
==> 在 iostre...@bbs.yuntech.edu.tw (怒向刀叢覓小 的文章中提到:
> > 你在說什麼呀???
> > 不拿掉 .h 的話, 編譯器會以為你所 #include 的是 ANSI C 的 <string.h>
> > 這可跟 ANSI C++ 的 <string> 的 std::string 沒有關係。
> > 哪個編譯器會聰明的把 #include <string.h> 看成是去引入 C++ 的 std::string,
> > 請告訴我。
> 以下這段程式碼在Borland C++ Builder 5.0 的編譯器是可執行的...

你寫的兩段程式都是作弊寫法。沒有做到控制變因。

既然我們探討的核心問題是「#include <string.h>」,
你就不應該在測試程式裡再去 #include 其他有的沒的來混淆主題,
畢竟你多去 #include 進來的東東, 搞不好會間接 #include <string>。

改寫你的第一支程式:

#include<string.h>
//#include<iostream.h> // 拿掉!
//#include<conio.h> // 拿掉!
//#include<cstring> // 拿掉!

// using namespace std;

int main(int argc, char* argv[])
{
string cc("hello");

// cout <<cc.c_str()<<endl<<strlen(cc.c_str()); // 拿掉!
// getch(); // 拿掉!

return 0;
}

> 至於以下這段程式在BCB5.0裡頭仍是可執行的 :

把你的第二支程式改寫成:

//#include<string> // 拿掉!
//#include<iostream> // 拿掉!
//#include<conio> // 拿掉!
#include<string.h>

using namespace std;

int main(int argc, char* argv[])
{
string cc("hello");

// cout <<cc.c_str()<<endl<<strlen(cc.c_str()); // 拿掉!
// getch(); // 拿掉!

return 0;
}

請再拿去試試哪個編譯器能成功編譯?

)

unread,
Sep 16, 2000, 3:00:00 AM9/16/00
to

怒向刀叢覓小詩

unread,
Sep 17, 2000, 12:40:35 AM9/17/00
to
※ 引述《willi...@cis.nctu.edu.tw (何陋居主)》之銘言:

> ==> 在 iostre...@bbs.yuntech.edu.tw (怒向刀叢覓小 的文章中提到:
> ^^^^^^^^^^^

> 你在說什麼呀???
> 不拿掉 .h 的話, 編譯器會以為你所 #include 的是 ANSI C 的 <string.h>
> 這可跟 ANSI C++ 的 <string> 的 std::string 沒有關係。
> 哪個編譯器會聰明的把 #include <string.h> 看成是去引入 C++ 的 std::string,
> 請告訴我。

不管有沒有作弊, 至少BCB的編譯器是蠻聰明的..

--
-------------------------------------------------------------------------------

Analyze a little, design a little, implement a little
, and test a little Grady Booch

--
[m※ Origin: 雲林科技大學藍天使 <bbs.yuntech.edu.tw> [From: 163.32.196.34]

0 new messages