错误:请求's' 中的成员'empty',它是非类类型'const char' 65 | if (s.empty() || s[s.size() - 1] == '.')

问题描述

我正在阅读 C++ 书籍 C++ Primer 5th Edition 在第 4 章中有一个代码

for (const auto &s : text)
{
    cout << s << " " << typeid(s).name() << " ";
    if (s.empty() || s[s.size() - 1] == '.')
        cout << endl;
    else
        cout << " "; // otherwise just separate with a space
}

当我运行此代码并使用文本字符串时,它给我一个错误,当我使用 char* 时也是如此

`op.cpp:65:9: error: request for member 'empty' in 's',which is of non-class type 'const   char'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)