mardi 21 décembre 2021

Syntax error; string is not being accepted in if statement. ( C++ ) [duplicate]

In this code I tried to use getline() for getting full sentence as input from user and show results. It's a very basic program. I was trying to make small interactive platform.

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int a;
    string b;
    string b1 = "I am fine";
    std::cout << "Hello, Enter 1 to continue...." << std::endl;
    std::cin >> a;
    if(a==1){
        std::cout << "How are you?" << std::endl;
        getline(std:: cin, b);
    }else{
        cout<<endl;
    }
    int c;
    if(b == b1){
        std::cout << "Gald to know that, press 2 to continue..." << std::endl;
        cin>>c;
    }else{
        std::cout<< "Bye" <<endl;
    }

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire