jeudi 27 avril 2017

Why scanf is not taking any input and giving Error in hackerearth editor and codeblocks

I want to take string input with white spaces. This is my code:

#include<iostream>
#include <stdio.h>
#include<string>

using namespace std;

int main()
{
    string name;

    printf("\nEnter the name : ");


    scanf ("%[^\n]%*c", name); //it does not work

    //getline(cin, name); //it works fine

    cout<<name<<endl;

    return 0;
}

Error Massage on hackerearth editor and codeblocks:

In function ‘int main()’: 16:29: error: cannot pass objects of non-trivially-copyable type ‘std::string {aka class std::basic_string}’ through ‘...’

16:29: warning: format ‘%[^ :string {aka std::basic_string}’ [-Wformat=] 16:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

Aucun commentaire:

Enregistrer un commentaire