Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example code for ifstream reading a json file results in no operator error #1766

Closed
desluOs opened this issue Sep 28, 2019 · 10 comments
Closed
Labels
platform: visual studio related to MSVC solution: invalid the issue is not related to the library state: needs more info the author of the issue needs to provide more details

Comments

@desluOs
Copy link

desluOs commented Sep 28, 2019

#include <nlohmann/json.hpp>
#include <iostream>
#include <fstream>
using namespace std;
using json = nlohmann::json;
void run() {
		ifstream in("test.json");
		json j;

		in >> j;

is where the problem occurs, with the >> the only thing resulting in an error. I got the setup from the example code for reading json files. This is happening in a header file. Everything compiles with warnings and will run, but errors out when it gets to this point.

C++ no operator matches these operands operand types are: std::ifstream >> json

is the exact text given when hovering over the red underlined >>;

Not sure what I'm missing, sorry if it's obvious but I tried to find a solution elsewhere first.

@MockusT
Copy link

MockusT commented Oct 5, 2019

Try changing version to 3.6.1. Should fix the problem (Wasn't working for me also on 3.7.0)

@nlohmann
Copy link
Owner

In order to asses your issue, we need the following information:

  • What is the issue you have?

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

  • What is the expected behavior?

  • And what is the actual behavior instead?

  • Which compiler and operating system are you using? Is it a supported compiler?

  • Did you use a released version of the library or the version from the develop branch?

  • If you experience a compilation error: can you compile and run the unit tests?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Oct 17, 2019
@mtissington
Copy link

I have the same issue and in addition I get an E0349 with Visual Studio 2019.

@nlohmann
Copy link
Owner

nlohmann commented Nov 2, 2019

Can you please paste the exact error message?

This code works without issues:

#include <iostream>
#include "json.hpp"
#include <fstream>

using json = nlohmann::json;

int main()
{
    std::ifstream in("test.json");
    nlohmann::json j;
    in >> j;
    std::cout << j << std::endl;
}

@TQwan
Copy link

TQwan commented Nov 4, 2019

I have the same problem, using Visual Studio 2019 with latest version (3.7.0)
Reverting back to 3.6.1 ( SHA-1: 1126c9c ) fixes the issue.

Problem is this line.
in >> j;
It seems the implementation of the >> operator has been removed in 3.7.

@nlohmann
Copy link
Owner

nlohmann commented Nov 4, 2019

No, we did no remove this operator, but only deprecate it.

@mtissington
Copy link

Here are the 3 errors I get

Severity Code Description Project File Line Suppression State
Error (active) E0349 no operator ">>" matches these operands

Severity Code Description Project File Line Suppression State
Error (active) E0065 expected a ';' ActiveWords DLL C:\ActiveWords4\ActiveWords DLL\json.hpp 18922

Severity Code Description Project File Line Suppression State
Error (active) E0079 expected a type specifier ActiveWords DLL C:\ActiveWords4\ActiveWords DLL\json.hpp 18921

@nlohmann
Copy link
Owner

nlohmann commented Nov 6, 2019

Which compiler are you using?

@mtissington
Copy link

mtissington commented Nov 6, 2019 via email

@nlohmann nlohmann added the platform: visual studio related to MSVC label Nov 7, 2019
@nlohmann
Copy link
Owner

nlohmann commented Nov 7, 2019

Seems to be related to #1704 #1702 #1756. In #1756, it is reported that a newer version of Visual Studio 2019 has fixed this issue (which is unrelated to this library).

@nlohmann nlohmann closed this as completed Nov 7, 2019
@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: visual studio related to MSVC solution: invalid the issue is not related to the library state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

5 participants