显示字符串的C++

C++ showing a string

本文关键字:C++ 字符串 显示      更新时间:2023-10-16

实际上我对c++有点陌生。如果答案不止一个,我想显示"问题";如果答案在一个以下,我想"问题"这些是错误吗我得到

    5   IntelliSense: no operator "<<" matches these operands
        operand types are: std::basic_ostream<char, std::char_traits<char>> << std::string  c:UsersUgwuDocumentsVisual Studio 2012ProjectsChrysohgomus_Ugwu_A4Chrysohgomus_Ugwu_A4mathTutor.cpp 46  39  Chrysohgomus_Ugwu_A4

或图像链接

这是我的代码

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的想法,但如果你要使用不带std::前缀的string,你必须添加using std。就我个人而言,我认为你最好坚持使用std::string。)