比较std :: string和C样式的字符串文字

问题描述 投票:6回答:1

假设我有以下代码:

#include <iostream>
#include <string>
#include <iomanip>
using namespace std; // or std::

int main()
{
    string s1{ "Apple" };
    cout << boolalpha;
    cout << (s1 == "Apple") << endl; //true
}

我的问题是:系统如何在这两者之间进行检查? s1是对象,而"Apple"C样式字符串文字。

据我所知,无法比较不同的数据类型。我在这里想念什么?

c++ comparison c-strings stdstring c++-standard-library
1个回答
12
投票
© www.soinside.com 2019 - 2024. All rights reserved.