簡體   English   中英

錯誤:“std::string_view”尚未聲明

[英]error: 'std::string_view' has not been declared

我正在嘗試從書中編譯一個示例問題。

在我的系統上編譯時出現錯誤,所以我嘗試了一個在線編譯器,它工作正常。 我將 g++ 更新到版本 9 並再次嘗試,但仍然無法編譯。 我收到錯誤'std::string_view' has not been declared

// Sorting words recursively
#include <iostream>
#include <iomanip>
#include <memory>
#include <string>
#include <string_view>
#include <vector>

using Words = std::vector<std::shared_ptr<std::string>>;

// Function prototypes
void swap(Words& words, size_t first, size_t second);
void sort(Words& words);
void sort(Words& words, size_t start, size_t end);
void extract_words(Words& words, std::string_view text, std::string_view separators);
void show_words(const Words& words);
size_t max_word_length(const Words& words);

第一個錯誤發生在extract_words原型中,之后所有嘗試使用text參數或任何使用std::string_view都會導致錯誤。

cppreference.com中所述, std::string_view僅在 c++17 或更新版本中可用。

為了使用它,在你的編譯器中啟用它。 對於 g++ 或 clang++,使用開關-std=c++17

經過一天半的編譯器升級,降級,瘋狂地弄亂參數設置,包括,不包括文件和目錄,閱讀了數十篇博客並遵循了許多指導,這就是解決方案使用開關-std=c++17謝謝給艾瑪迪斯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM