1)-6ren">
gpt4 book ai didi

C++ 显示一个字符串

转载 作者:太空宇宙 更新时间:2023-11-04 11:25:54 25 4
gpt4 key购买 nike

实际上我是 c++ 的新手。如果答案不止一个,我想显示“问题”,如果答案在一个以下,我想显示“问题”这些是我得到的错误

    5   IntelliSense: no operator "<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char>> << std::string c:\Users\Ugwu\Documents\Visual Studio 2012\Projects\Chrysohgomus_Ugwu_A4\Chrysohgomus_Ugwu_A4\mathTutor.cpp 46 39 Chrysohgomus_Ugwu_A4

Image Link

这是我的代码

string Question;

void grade() {
question = correct + incorrect;
if (question > 1){
Question = "Questions";
}
else{
Question = "Question";
}
cout << "Out Of " << question << " " << Question << " You Got " << correct << " Correct " << "And " << incorrect << " Incorrect " << endl;
}

谁能告诉我正确的方法?

最佳答案

一个可能的问题是正确或不正确都不是 cout 可打印的对象。

您也可能没有包含 <string>在你的程序中正确。你加了吗#include <string>using std在你的代码中?

(当然,我真的不支持 using std 的想法,但是如果你打算使用没有 string 前缀的 std::,你必须添加 using std 。就我个人而言,我认为你坚持使用 std::string 会更好。)

关于C++ 显示一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26696509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com