Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ scanf was not declared in this scope

Here's my code

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

using namespace std;

int main()
{
    long long int N = 0, product, sum;
    int t; scanf_s("%d", &t);  //// ERROR STARTS AT THIS LINE
    while (t--)
    {
        sum = 0;

        scanf_s("%d", &N);
        N = N / 2;

        product = 1;
        sum = 1; 
        for (int i = 1; i <= N; i++)
        {
            product = product * i;
            sum += product;
        }

        printf("%d \n", sum);
    }
    return 0;
}

I get this compiling error when submitting solution to www.codechef.com

prog.cpp: In function 'int main()':
prog.cpp:9:25: error: 'scanf_s' was not declared in this scope
  int t; scanf_s("%d", &t);

I have tried compiling with C++ (gcc-4.3.2), (C++ gcc-4.9.2) and C++ 14 (g++4.9.2), didn't work. Why..? I have included <stdio.h>.

like image 486
JJChai Avatar asked Sep 12 '25 00:09

JJChai


1 Answers

You can change scanf_s to scanf.

like image 75
hassan ghalami Avatar answered Sep 13 '25 18:09

hassan ghalami