1. 程式人生 > >C++Primer--->#include與#include以及#inclue 和 #include的區別

C++Primer--->#include與#include以及#inclue 和 #include的區別

2.為什麼下面這段程式碼
#include <string.h>
void main()
{
     string aaa= "abcsd d";
     printf("looking for abc from abcdecd %s\n",
         (strcmp(aaa,"abc")) ? "Found" : "Not Found");
}
不能正確執行,說是string型別沒有定義
而下面:
#include <string>
using namespace std;
void main()
{
     string aaa= "abcsd d";
     printf("looking for abc from abcdecd %s\n",
         (strcmp(aaa,"abc")) ? "Found" : "Not Found");
}
這裡的string編譯器就認識了,但是strcmp就不認識了呢?
---------------------------------------------------------------
一般一個C++的老的帶“.h”副檔名的庫檔案,比如iostream.h,在新標準後的標準庫中都有一個不帶“.h”副檔名的相對應,區別除了後者的好多改進之外,還有一點就是後者的東東都塞進了“std”名字空間中。
但唯獨string特別。
問題在於C++要相容C的標準庫,而C的標準庫裡碰巧也已經有一個名字叫做“string.h”的標頭檔案,包含一些常用的C字串處理函式,比如樓主提到的strcmp。
這個標頭檔案跟C++的string類半點關係也沒有,所以<string>並非<string.h>的“升級版本”,他們是毫無關係的兩個標頭檔案。

要達到樓主的目的,比如同時: