依照軟體的特性有所不同吧...
在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]
你在說什麼呀???
不拿掉 .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>
> 你在說什麼呀???
> 不拿掉 .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;
你寫的兩段程式都是作弊寫法。沒有做到控制變因。
既然我們探討的核心問題是「#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;
}
請再拿去試試哪個編譯器能成功編譯?
不管有沒有作弊, 至少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]