久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么省略“#include <string>"?只是有時會

Why does omission of quot;#include lt;stringgt;quot; only sometimes cause compilation failures?(為什么省略“#include string?只是有時會導致編譯失敗?)
本文介紹了為什么省略“#include <string>"?只是有時會導致編譯失敗?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我是 C++ 的初學者.當我編寫代碼時,有時我會寫 #include 并且代碼有效,有時我不寫 #include 并且代碼沒有不行.但有時它可以在沒有 #include 的情況下工作.

I am a beginner with C++. When I write the code sometimes I write #include <string> and the code works, other times I don't write #include <string> and the code doesn't work. But sometimes it works without #include <string>.

那么我是否必須編寫 #include <string> 才能使代碼有效?

So do I have to write #include <string> so that the code works?

推薦答案

如果您使用在標準標頭 string 內聲明的成員,那么是的,您必須直接或間接包含該標頭(通過其他標題).

If you use members that are declared inside the standard header string then yes, you have to include that header either directly or indirectly (via other headers).

某些 編譯器在 some 平臺上可能會在每月的 某些 時間編譯,即使您沒有包含頭文件.這種行為令人遺憾、不可靠,并不意味著您不應包含標題.

Some compilers on some platforms may on some time of the month compile even though you failed to include the header. This behaviour is unfortunate, unreliable and does not mean that you shouldn’t include the header.

原因很簡單,您包含了其他標準標題,恰好包含string.但正如我所說,這通常不能依賴,它也可能會突然發生變化(例如,當安裝了新版本的編譯器時).

The reason is simply that you have included other standard headers which also happen to include string. But as I said, this can in general not be relied on and it may also change very suddenly (when a new version of the compiler is installed, for instance).

始終包含所有必要的標題.不幸的是,似乎沒有可靠的在線文檔來說明需要包含哪些標題.查閱一本書或官方的 C++ 標準.

Always include all necessary headers. Unfortunately, there does not appear to be a reliable online documentation on which headers need to be included. Consult a book, or the official C++ standard.

例如,以下代碼使用我的編譯器 (gcc 4.6) 進行編譯:

For instance, the following code compiles with my compiler (gcc 4.6):

#include <iostream>

int main() {
    std::string str;
}

但是如果我刪除第一行,即使 iostream 標頭實際上應該是無關的,它也不再編譯.

But if I remove the first line, it no longer compiles even though the iostream header should actually be unrelated.

這篇關于為什么省略“#include <string>"?只是有時會導致編譯失敗?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

boost_1_60_0 .zip installation in windows(Windows 中的 boost_1_60_0 .zip 安裝)
How do I get console output in C++ with a Windows program?(如何使用 Windows 程序在 C++ 中獲得控制臺輸出?)
How do I calculate the week number given a date?(如何計算給定日期的周數?)
OpenCV with Network Cameras(帶有網絡攝像機的 OpenCV)
Export all symbols when creating a DLL(創建 DLL 時導出所有符號)
Getting started with OpenCV 2.4 and MinGW on Windows 7(Windows 7 上的 OpenCV 2.4 和 MinGW 入門)
主站蜘蛛池模板: 四虎在线观看 | 97偷拍视频 | 九九热国产精品视频 | 7777精品伊人久久精品影视 | 精品一区二区三区四区视频 | 澳门永久av免费网站 | 精品国产91乱码一区二区三区 | 久久曰视频 | 中文字幕国产第一页 | 91麻豆精品国产91久久久更新资源速度超快 | 国产精品美女www爽爽爽视频 | 国产美女久久久 | 日韩欧美不卡 | 国产一区二区三区在线视频 | 欧美jizzhd精品欧美巨大免费 | 国产精品视频在线播放 | 午夜爱爱毛片xxxx视频免费看 | 成人一区二区三区在线 | 污免费网站 | 91中文在线观看 | 色综合久久88色综合天天 | 亚洲网站在线播放 | 精品国产色 | 亚洲成人免费视频在线 | 日韩a v在线免费观看 | 在线一级片 | 97国产精品视频人人做人人爱 | 久久久久久久久91 | 亚洲国产精品一区二区久久 | 欧美国产亚洲一区二区 | 精品视频在线免费观看 | 亚洲视频精品 | 欧美在线看片 | 欧美日韩国产精品一区 | 国产精品久久久久永久免费观看 | 亚洲福利片 | 久久久久国产精品午夜一区 | 黄色大片毛片 | 懂色中文一区二区三区在线视频 | 国产精品久久久久久久久久久久 | 欧美日韩在线成人 |