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

為什么省略“#include <string>"?只是有時(shí)會(huì)

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

問題描述

我是 C++ 的初學(xué)者.當(dāng)我編寫代碼時(shí),有時(shí)我會(huì)寫 #include 并且代碼有效,有時(shí)我不寫 #include 并且代碼沒有不行.但有時(shí)它可以在沒有 #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?

推薦答案

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

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 平臺(tái)上可能會(huì)在每月的 某些 時(shí)間編譯,即使您沒有包含頭文件.這種行為令人遺憾、不可靠,并不意味著您不應(yīng)包含標(biāo)題.

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.

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

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).

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

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) 進(jìn)行編譯:

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

#include <iostream>

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

但是如果我刪除第一行,即使 iostream 標(biāo)頭實(shí)際上應(yīng)該是無關(guān)的,它也不再編譯.

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

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

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

相關(guā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++ 中獲得控制臺(tái)輸出?)
How do I calculate the week number given a date?(如何計(jì)算給定日期的周數(shù)?)
OpenCV with Network Cameras(帶有網(wǎng)絡(luò)攝像機(jī)的 OpenCV)
Export all symbols when creating a DLL(創(chuàng)建 DLL 時(shí)導(dǎo)出所有符號(hào))
Getting started with OpenCV 2.4 and MinGW on Windows 7(Windows 7 上的 OpenCV 2.4 和 MinGW 入門)
主站蜘蛛池模板: 香蕉视频色 | 国产精品一区在线播放 | 夜夜操影院 | 天天艹夜夜艹 | 免费av网站在线观看 | av大全在线观看 | 欧美性久久 | 一区在线视频 | 亚洲香蕉视频 | 老司机久久| 欧美日韩国产在线播放 | 欧美操 | 日韩免费在线视频 | 国内精品一区二区三区 | 欧美精品在线观看视频 | 日本在线观看一区 | 草草福利影院 | 亚洲成人一区二区 | 欧美性生活网站 | 久久精品免费观看 | 在线一区视频 | 草草免费视频 | 日韩久久久久久久 | 日韩欧美中文 | xxxxx国产| 天天插天天射 | 22精品一区二区三区 | 国产精品欧美精品 | 色激情网| 精品1区2区3区 | 成年人的免费视频 | 国内精品国产成人国产三级 | 精品国产乱码久久久久久蜜臀网站 | 日本免费观看视频 | 欧美一区二区在线播放 | 午夜美女福利视频 | 国产午夜精品久久久久久久 | 欧美精品99久久久 | 香蕉视频在线看 | 毛片在线免费 | 能看的av网站 |