Unable to compile simple jsoncpp program with Eclipse on LInux - c++

The File is at the location /home/shivang/Desktop and the filename is sh1.cpp
Source code for the file is given below
#include iostream
#include json/json.h
#include json/reader.h
using namespace std;
using namespace Json;
int main() {
std::string example = "{\"array\":[\"item1\", \"item2\"], \"not an array\":\"asdf\"}";
Value value;
Reader reader;
bool parsed = reader.parse(example, value, false);
std::cout << parsed;
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
The following error messages are displayed.
/home/shivang/Desktop/sh1.cpp: In function ‘int main()’:
/home/shivang/Desktop/sh1.cpp:10:2: error: ‘Value’ was not declared in this scope
/home/shivang/Desktop/sh1.cpp:10:8: error: expected ‘;’ before ‘value’
/home/shivang/Desktop/sh1.cpp:11:2: error: ‘Reader’ was not declared in this scope
/home/shivang/Desktop/sh1.cpp:11:9: error: expected ‘;’ before ‘reader’
/home/shivang/Desktop/sh1.cpp:13:16: error: ‘reader’ was not declared in this scope
/home/shivang/Desktop/sh1.cpp:13:38: error: ‘value’ was not declared in this scope
Configuration gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)
jsoncpp-src-0.5.0
eclipse-cpp-helios-SR2-linux-gtk

I have never used Json or C++ before. But a little googling around led me to this page. I think adding the following line to your list of includes should help:
#include <json/value.h>

Related

Getting an weird error in vscode when i'm trying to run a code

When I'm trying to run a simple hello world script it sends this error message, Can anyone help me solving this issue?
[Running] cd "c:\Users\NickT\OneDrive\Documents\C++ Tutorial\" && g++ helloworld.cpp -o helloworld && "c:\Users\NickT\OneDrive\Documents\C++ Tutorial\"helloworld
helloworld.cpp: In function `int main()':
helloworld.cpp:9: error: expected primary-expression before "msg"
helloworld.cpp:9: error: expected `;' before "msg"
helloworld.cpp:11: error: expected primary-expression before "const"
helloworld.cpp:11: error: expected `;' before "const"
helloworld.cpp:16: error: expected primary-expression before '}' token
helloworld.cpp:16: error: expected `)' before '}' token
helloworld.cpp:16: error: expected primary-expression before '}' token
helloworld.cpp:16: error: expected `;' before '}' token
[Done] exited with code=1 in 0.233 seconds
This is the written code
#include <iostream>
int main(){
std::cout << "Hello World" << std::endl;
return 0;
}
I revised the code you have posted as well as added a piece of code to utilize the namespace std. Analyzing the output from your compiler it does seem that you may have not added a semi colon. Alternatively, it's not necessary to reference the std library when calling it's functions but it's up to your preference. It doesn't seem though to be an issue with your code either. Can you post the actual code you've attempted to compile because there doesn't seem to be an issue with this piece.
Revised Code:
#include <iostream>
using namespace std;
int main() {
std::cout << "Hello World" << std::endl;
return 0;
}

Compiler Issues : iostream not working

When i compile my c++ code using g++ 5.1.1 it says
"narc05b.cpp: In function ‘int main()’:
anarc05b.cpp:5:3: error: ‘cout’ was not declared in this scope
cout<<"hello\n"; ^ anarc05b.cpp:5:3: note: suggested alternative:
In file included from anarc05b.cpp:1:0:
/usr/include/c++/5.1.1/iostream:61:18: note: ‘std::cout’ extern
ostream cout; /// Linked to standard output "
...what does it mean ?
Use should use the namespace directive in the code
using namespace std;
or alternatively prefix cout with std::cout

C++ Function was not declared in this scope error

I am compiling a code, but I seem to get an error, even as I examine my code, I find it weird that I'm getting this error.
My code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "2A";
int n = stoul(s, nullptr, 16);
cout << n << endl;
return 0;
}
and in the command line, I'm typing g++ -std=c++11 main.cpp, I'm using -std=c++11 because the function stoul is from C++11 according to this page stoul.
The error I'm getting is the following:
main.cpp: In function 'int main()':
main.cpp:8:30: error: 'stoul' was not declared in this scope
int n = stoul(s, nullptr, 16);
^
Why am I getting this error?

Compiler error: 'expected unqualified-id before "using'''

Here is my code:
//test file
#include <iostream>
#include "stat.h"
#include "frequency.h"
using namespace std;
int main(){
cout << "helo"<< endl;
return 0;
}
When I try to compile, I get:
test.cc:7: error: expected unqualified-id before "using"
test.cc:7: error: expected `,' or `;' before "using"
Any idea what is going on here?
You probably missed the ; in the end of the header file.
It should look like this:
class frequency {
...
};
The problem is likely an error in the last line of frequency.h.

LEDA programming with c++:

I am a LEDA-6.3 user.
I have an error when compiling this simple code:
#include <LEDA/core/d_array.h>
#include <iostream>
using namespace std;
main()
{
d_array<string,string> dic;
dic["hello"] = "hallo";
dic["world"] = "Welt";
dic["book"] = "Buch";
dic["key"] = "Schluessel";
string s;
forall_defined(s,dic) cout << s << " " << dic[s] << endl;
}
G++ Compiler:
g++ -I$LEDAROOT/incl -L$LEDAROOT d_array.cpp /usr/lib/LEDA/libleda.a -lX11 -lm -o d_array
The ERROR:
d_array.cpp: In function ‘int main()’:
d_array.cpp:8: error: ‘d_array’ was not declared in this scope
d_array.cpp:8: error: expected primary-expression before ‘,’ token
d_array.cpp:8: error: expected primary-expression before ‘>’ token
d_array.cpp:8: error: ‘dic’ was not declared in this scope
Please if there is a guide for LEDA-6.3 give me the link
You probably mean leda::d_array or are forgetting using namespace leda;