我是 C++ 的完全菜鸟,我遇到的第一个问题如下:
没有运算符 >> 匹配这些操作数
#include "pch.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "hello world!";
cin >> "hello world!";
}
Run Code Online (Sandbox Code Playgroud)
std::cin需要写入一个变量,但您传递给它的是一个const char[13]字符串文字。
你需要传递类似 a 的东西std::string:
std::string str;
std::cin >> str;
Run Code Online (Sandbox Code Playgroud)
PS 这是 a) 阅读编译器消息,b)using namespace std;全局避免,c) 获得一本好的 C++ 书籍的好时机。