rapidjson + c++: "abort() has been called" error - c++

I need to parse json in my C++ program. I decided to use RapidJson library for this purpose, but I got "abort() has been called" error. I truncated the code to this:
#include <iostream>
#include <cstdlib>
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/encodings.h"
#include "rapidjson/stringbuffer.h"
using namespace std;
using namespace rapidjson;
typedef GenericDocument<UTF16<> > WDocument;
typedef GenericValue<UTF16<> > WValue;
wchar_t request[] = L"{\"result\":\"OK\"}";
int main()
{
WDocument d;
d.Parse(request);
WValue& v = d[L"result"]; // The exception throws here
if (wcscmp(v.GetString(), L"OK"))
{
cout << "Success!" << endl;
}
else
cout << "Fail!" << endl;
system("pause");
return 0;
}
but I got the error again. Where is the mistake? Thanks in advance!

check this line:
wchar_t request[] = L"{\"result\":\"OK\"}";
there is a character before the left brace.

Related

c++ getter not returning value (NULL)

when i try to cout the get function it don't return any value !
my header file :
#pragma once
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class Dog
{
private:
string dogName = "Max";
public:
Dog();
void talking();
void jumping();
void setDogName(string newDogName);
///////thats the function /////
string getDogName();
};
my cpp file :
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Dog.h"
using namespace std;
Dog::Dog() {
cout << " Dog has been Created " << endl;
}
void Dog::setDogName(string newDogName)
{
newDogName = dogName;
}
string Dog::getDogName()
{
return dogName;
}
and my main.cpp file:
#include "stdafx.h"
#include <iostream>
#include "Dog.h"
#include "Cat.h"
int main()
{
Dog ewila;
ewila.setDogName("3wila");
cout << ewila.getDogName();
return 0;
}
im learning c++ new so i don't know whats happening even i tried to type ewila.getDogName(); by itself and it didn't do anything
and i tried to store the setDogname() in a variable to return with the getDogName() and also nothing i don't know what i'm doing wrong
also : im using visual studio 2017 and i run the program from visual c++ 2015 MSBuild command prompt
The problem is in line newDogName = dogName; of function void Dog::setDogName(string newDogName). You are using assignment operator(=) incorrectly. This should be dogName =newDogName;
So the corrected CPP file will be:
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Dog.h"
using namespace std;
Dog::Dog() {
cout << " Dog has been Created " << endl;
}
void Dog::setDogName(string newDogName)
{
dogName = newDogName;
}
string Dog::getDogName()
{
return dogName;
}

"endl" causes "C1001" error

My code is a basic HelloWorld but fails to compile when I use cout<<endl.
I'm using Microsoft visual studio fresh download and created a console application for my first test project.
// Test1ConsoleApplication.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
//#include <ostream>
using namespace std;
int main()
{
string s = "hello world!!";
cout << "lets see: " << s << endl;
return 0;
}
It generates a
"C1001" at line 1.
Replacing "endl" with ""\n"" works though.
You don't need the precompiled header #include <stdafx.h> so you can safely get rid of it. Also get rid of using namespace std; because it pollutes the global namespace. Try something like this. There's no reason it shouldn't work.
#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;
int main()
{
string s = "hello world!!";
cout << "lets see: " << s << endl;
return 0;
}
In Visual Studio you can disable use of the precompiled header in the project settings.
I do not see what the problem is. Both options compile and execute for me.
RexTester cppOnline
// Test1ConsoleApplication.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <string>
#include <iostream>
//#include <ostream>
using namespace std;
int main()
{
string s = "hello world!!";
cout << "lets see: " << s << endl;
cout << "lets see: " << s << "\n";
return 0;
}
So idk what was causing the error but it was fixed after pasting imports to the "stdafx.h" header file and then delete them...

ncurses getch() weird output?

I have installed the ncurses.h lib and started experimenting with the getch() function.When I built and run this code which seems alright to me at first, the console printed out a weird character: '�'(if it doesn't show and shows as a space here is a screen shot: https://prnt.sc/gbrp7b) The console starts spamming it but if I type a character, it shows up in the output but still the '�' spams. Here is the code:
#include <iostream>
#include <fstream>
#include <ncurses.h>
using namespace std;
int main(){
char input;
while(true){
input = getch();
cout << "You entered : " << input << endl;
//break;
}
return 0;
}
So I thought of trying to use an if statement to try and stop it spamming but the code doesn't recognise the character:
It gives this error:
error: character too large for enclosing character literal type
For this code:
#include <iostream>
#include <fstream>
#include <ncurses.h>
using namespace std;
int main(){
char input;
while(true){
input = getch();
if(input!='�'){
cout << "YOu entered : " << input << endl;
}
}
return 0;
}
I am on OSX Sierra 10.12.5 and using eclipse Oxygen
You need to initialize ncurses with initscr() and close it with endwin() functions:
#include <iostream>
#include <fstream>
#include <ncurses.h>
using namespace std;
int main(){
char input;
initscr();
while (true) {
input = getch();
cout << "YOu entered : " << input << endl;
}
endwin();
return 0;
}

Visual Studio 2015: Getting "non standard syntax, use '&' to create a pointer to member" error

Super confused as to what is throwing the error when I try to compile my code. I'm currently trying to test a function I wrote by printing out the values it should extract from a file.
gameboard.cpp
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include "error.h"
using namespace std;
int boardDim(ifstream & inputFile, unsigned int x, unsigned int y) {
inputFile.open; //error is thrown here
if (!(inputFile.is_open())) {
throw fileNotOpen;
}
else {
stringstream output(inputFile.getline); //error is also thrown here
if (output >> x) {
if (output >> y) {
return success;
}
return secBoardVarErr;
}
return firstBoardVarErr;
}
cout << x << endl;
cout << y << endl;
}
gameboard.h
#ifndef GAMEBOARD_H
#define GAMEBOARD_H
#include <iostream>
using namespace std;
//takes in dimensions of board from file
int boardDim(ifstream &, unsigned int, unsigned int);
#endif !GAMEBOARD_H
main function
#include "stdafx.h"
#include "functions.h"
#include "gamepieces.h"
#include "gameboard.h"
#include "error.h"
int main(int argc, char * argv[])
{
ifstream x("test.txt");
int test = 0;
cout << boardDim(x, 0, 0) << endl;
return success;
}
I'm only testing the function I declared and defined in the gameboard header and source files, so the other included files will be used in the future but have already been tested and are not throwing errors when I compile and run it.
Thank you!
inputFile.open is a function, same with inputFile.getline, so what you have here is a syntactic error. The correct syntax is:
inputFile.open()
and
inputFile.getline()

Launching a program with Voce

I've compiled with success my first program with the Voce library but when I start the program, it stops right after. I can't say any word and it stops
#include <iostream>
#include <string>
#include <voce.h>
#include <windows.h>
using namespace std;
int main()
{
voce::init("voce/lib", false, true, "voce/lib/grams", "digits");
while (voce::getRecognizerQueueSize() > 0)
{
std::string s = voce::popRecognizedString();
std::cout << "You said: " << s << std::endl;
}
system("PAUSE");
return 0;
}
I took this code on : http://voce.sourceforge.net/
Thank you for your help