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