I'm getting an error when I try to query an object using a string variable, but not when I directly use a string.
JSON:
{"x": "hello"}
This works:
std::cout << document["x"].GetString();
This doesn't work:
std::string s = "x";
std::cout << document[s].GetString();
I'm getting this error:
error: no viable overloaded operator[] for type 'rapidjson::Document'
(aka 'GenericDocument<UTF8<> >')
std::cout << document[s].GetString();
~~~~~^~
note: candidate function not viable: no known conversion from 'std::string'
(aka 'basic_string<char, char_traits<char>, allocator<char> >') to 'SizeType'
(aka 'unsigned int') for 1st argument
What am I doing wrong?
Try
std::cout << document[s.c_str()].GetString();
It seems the operator was not overloaded for a std::string but for a C-string.
(Reference for the c_str member function)
Related
I am trying to implement an MLP using HLS4ML following the tutorial https://github.com/Gabriele-bot/PYNQ_IA/blob/main/NN_train/MNIST_Test/MNIST_CNN_train.ipynb
The command to synthesize the generated C files
hls_model.build(csim=False,synth=True,export=True)
produces the error
error: use of overloaded operator '<<' is ambiguous (with operand
types 'basic_ostream<char, std::char_traits >' and 'const T_in'
(aka 'const ap_fixed<8, 3>'))
I have tried synthesizing the design using Vivado HLS 2018.3 and 2020.1. But both produces similar error. Has anybody experienced and resolved such errors with HLS4ML generated codes?
The failed synthesis report shows a long list of candidates, such as the following:
ERROR: [HLS 200-70] Compilation errors found: In file included from
firmware/myproject_axi.cpp:1: In file included from
firmware/myproject_axi.cpp:1: firmware/myproject_axi.h:17:35: error:
use of overloaded operator '<<' is ambiguous (with operand types
'basic_ostream<char, std::char_traits >' and 'const T_in' (aka
'const ap_fixed<8, 2>'))
{ return stream << "{ data: " << in.data << ", last: " << in.last << " }" << std::endl; }
~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~
/tools/Xilinx/Vivado/2020.1/lnx64/tools/gcc/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/ostream:166:7:
note: candidate function
operator<<(long __n)
^
/tools/Xilinx/Vivado/2020.1/lnx64/tools/gcc/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/ostream:170:7:
note: candidate function
operator<<(unsigned long __n)
^ /tools/Xilinx/Vivado/2020.1/lnx64/tools/gcc/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../include/c++/4.6.3/ostream:174:7:
note: candidate function
operator<<(bool __n)
I am also attaching a screen capture of the myproject_axi.h file which is creating the issue.
I get Idmachine with GetVolumeInformation command. I want changed idmachine (DWORD) to string then show in TEdit(C++ builder) but not. Please help me!
GetVolumeInformation(L"C:\\",NULL,NULL,&dwVolSerial,NULL,NULL,NULL,NULL);
std::wstring wstr = std::to_wstring(idmachine);
std::string str = std::string(wstr.begin(), wstr.end());
ShowMessage(str);
Error
Vcl.Dialogs.hpp(1430): candidate function not viable: no known conversion from 'std::string' (aka 'basic_string, allocator >') to 'const System::UnicodeString' for 1st argument
In clang there is this file. I'm trying to reference one of the overloaded methods:
00909 std::string getAsString(const PrintingPolicy &Policy) const;
I tried:
std::__cxx11::basic_string<char> (&p2)(const clang::PrintingPolicy&) = &clang::QualType::getAsString;
and got:
REPL:1:73: error: address of overloaded function 'getAsString' does not match required type 'std::__cxx11::basic_string<char> (const clang::PrintingPolicy &)'
std::__cxx11::basic_string<char> (&p2)(const clang::PrintingPolicy&) = &clang::QualType::getAsString
/home/a/julia/usr/bin/../include/clang/AST/Type.h:905:15: note: candidate function has different qualifiers **(expected none but found const)**
std::string getAsString(const PrintingPolicy &Policy) const;
I also tried:
std::__cxx11::basic_string<char> (&p1)(clang::PrintingPolicy&) = &clang::QualType::getAsString;
and got:
candidate function has type mismatch at 1st parameter **(expected 'clang::PrintingPolicy &' but has 'const clang::PrintingPolicy &')**
Am I doing something wrong or is the compiler broken?
I am getting a cast error using the variable RockElem. The variable is defined in a class with other variables which are integers. This variable is defined as const.
if(resistivitySolve)
fileName << "_resist";
else if(dynamic_cast< const Water* >(fluid) != 0)
fileName << "_water";
else
fileName << "_oil";
fileName << "_sw_" << waterSat*100.0;
sort(m_throatConductances.begin(), m_throatConductances.end(), throatIndexCompare());
pair<const RockElem*, double> dummy(0, 0.0);
int idx(-99);
for(size_t i = 0; i < m_throatConductances.size(); ++i)
{
int tmp(m_throatConductances[i].first->orenIndex());
if(tmp == idx) m_throatConductances[i] = dummy;
idx = tmp;
}
The error i get is
error C2440: 'initializing' : cannot convert from 'int' to 'const RockElem *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
The error is with this part of the class- using a const before the term RockElem*
[
_Ty1=const RockElem *,
_Ty2=double,
_Ty=int,
_Other1=int,
_Other2=double
]
see reference to function template instantiation 'std::_Pair_base<_Ty1,_Ty2>::_Pair_base<_Ty,double>(_Other1 &&,_Other2 &&)' being compiled
The line of code using this is
pair<RockElem*, double> dummy(0, 0.0);
Is this not set properly?
The error message
error C2440: 'initializing' : cannot convert from 'int' to 'const
RockElem *' 1>
is clear enough. You are trying to convert an object of an integral type to pointer RockElem *. Are you sure you want to do this? If so then follow the advice of the compiler you gave in the error message.
Any idea why this gives a compile error?
std::unordered_map<int,int> mymap;
std::for_each(mymap.begin, mymap.end(), [](std::unordered_map<int, int>::value_type mapval) {
std::cout << mapval.first << ",";
});
error: conversion from â<unresolved overloaded function type>â to non-scalar type âstd::_Rb_tree_iterator<std::pair<const int, int> >â requested
mymap.begin()
You're missing the (), begin is a member function, not a data member.