0

I am coding in Visual Studio Code, using C++. I am getting the following error, "no operator >> matches these operands". Can you please tell me what I am doing wrong? (The error is occurring on the line, fin >> N.)

#include <fstream>

int solve() {
    std::ifstream fin;
    fin.open("race3.in");
    int N;
    fin>>N;

    std::ofstream fout;
    fout.open("race3.out");

    fout.close();
    fin.close();
}
walnut
  • 21,629
  • 4
  • 23
  • 59
Mihir Shah
  • 39
  • 1
  • 5
  • 2
    Can you please provide the full error message? (There should be more information below this line in the output.) I cannot reproduce your error. The only problem I see is that your function does not return a value although it is declared to do so. – walnut Nov 03 '19 at 03:01
  • Hello, here is the full error message: 'no operator ">>" matches these operands -- operand types are: std::ifstream >> int' at: '31,8' source: '' code: 'undefined'. My compiler is MinGW – Mihir Shah Nov 03 '19 at 03:05
  • In particular, we need to know what compiler you use. –  Nov 03 '19 at 03:06
  • @MihirShah Is that output from the actual compilation or is it just a hint from your IDE? MinGW's error messages look different. – walnut Nov 03 '19 at 03:07
  • I went to the command line and ran g++ filename.cpp, and I got no error. However Visual Studio Code is still showing the error. – Mihir Shah Nov 03 '19 at 03:10
  • @MihirShah Then this is not a problem with your code, but a problem with the VS Code settings. Since I don't know about them, someone else will have to answer that. – walnut Nov 03 '19 at 03:12
  • Are you completely sure that VS code uses MinGW? Can you also attach a screenshot of the problem? –  Nov 03 '19 at 03:12
  • Sorry I fixed the problem, the intellisense mode was set to msvc-x64. I set it to clang-x64 and the error disappeared. Thank you! – Mihir Shah Nov 03 '19 at 03:15
  • It's still strange. I tested it with msvc-x64: https://godbolt.org/z/Br888q . You may want to report a bug. –  Nov 03 '19 at 03:18
  • Note that [intellisense errors don't matter](https://stackoverflow.com/q/31943634/10957435) really because they can be finicky. What ultimately matters is does it compile when you hit "compile" and does the compiler throw an error (or warning)? If it does, then you actually have a problem. –  Nov 03 '19 at 06:03
  • 1
    @dyukha As OP commented, this is not actually a compilation error. They simply had setup their IDE wrong and presumably it was looking in the wrong directory for include files or something like that. – walnut Nov 03 '19 at 14:28

1 Answers1

0

So, from the comments, it seems to be a Intellisense problem.

I should note that in the future, that Intellisense can be finicky and prone to errors occasionally.

The best way to know that you really have an error is to hit "compile" and see what comes back. If it gives you an error message, then there is really something wrong. If it doesn't, then Intellisense could just be acting up.

As for this specific case, there looks like there is nothing wrong with your code, so it is likely just an Intellisense error. Here are some possible causes, but there is no way to know for sure this side of the computer.