久久久久久久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.但正如我所說,這通常不能依賴,它也可能會突然發(fā)生變化(例如,當安裝了新版本的編譯器時).

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模板網!

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

相關文檔推薦

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?(如何計算給定日期的周數(shù)?)
OpenCV with Network Cameras(帶有網絡攝像機的 OpenCV)
Export all symbols when creating a DLL(創(chuàng)建 DLL 時導出所有符號)
Getting started with OpenCV 2.4 and MinGW on Windows 7(Windows 7 上的 OpenCV 2.4 和 MinGW 入門)
主站蜘蛛池模板: 99热都是精品 | 精品日本久久久久久久久久 | 美国a级毛片免费视频 | 国产色在线 | 综合网伊人| 久久小视频| 免费国产视频在线观看 | 一二三四在线视频观看社区 | 四虎影音 | 91在线看网站 | 日韩精品一区二区三区视频播放 | 欧美久久久久久 | 日韩精品一二三 | 午夜精品久久久久久久久久久久久 | 黄色欧美视频 | 国产91久久精品一区二区 | 蜜桃一区二区三区在线 | 99久视频| 欧美综合一区 | 超碰成人av | 婷婷综合色 | 亚洲精品9999 | 国产激情在线 | 一区二区在线不卡 | 久久久久久亚洲 | 国产 亚洲 网红 主播 | 精品福利一区二区三区 | 色婷婷av一区二区三区软件 | 久久免费视频观看 | 一区二区三区国产精品 | av一区二区三区 | 99国产欧美| 亚洲精品高清视频在线观看 | 亚洲精品电影在线观看 | 亚洲免费一区二区 | 久久国产一区二区三区 | 欧美一区二区三区 | 国产精品视频久久 | 国产一区二区日韩 | 成人在线观看网址 | 成人aaa视频|