i have a question about a simple c++ function. This is my cpp file:
#include <string>
#include <iostream>
#include <stdio.h>
#include <ros/ros.h>
#include <json_prolog/prolog.h>
using namespace std;
using namespace json_prolog;
int main(int argc, char *argv[])
{
ros::init(argc, argv, "Knives");
Prolog pl;
char M[]="drawer";
cout<<M<<endl;
if(strcmp(M,"knife")==0)
{
string q= "rdfs_individual_of(M, 'http://knowrob.org/kb/knowrob.owl#TableKnife')";
PrologQueryProxy bdgs = pl.query(q);
cout<< endl;
for(PrologQueryProxy::iterator it=bdgs.begin(); it != bdgs.end(); it++)
{
PrologBindings bdg = *it;
cout << "Knives individuals= "<< bdg["M"] << endl;
}
cout<< endl<< endl;
}
if(strcmp(M,"drawer")==0)
{
string q= "rdfs_individual_of(M, 'http://knowrob.org/kb/knowrob.owl#Drawer')";
PrologQueryProxy bdgs = pl.query(q);
cout<< endl;
for(PrologQueryProxy::iterator it=bdgs.begin(); it != bdgs.end(); it++)
{
PrologBindings bdg = *it;
cout << "Drawer individuals= "<< bdg["M"] << endl;
}
cout<< endl<< endl;
}
return 0;
}
this code is connect with an xml file to parse it. if i compile it works and i have no problems. Now i have to change it,because i don't want to define the variable char M but i want to give it in input. the problem is that i change :
char M[]=....
with:
char M;
cin>>M;
i have a problem about the conversion from char to const char [-fpermissive]
how i can solve it?
try this:
std::string M;
cin >> M;
replace lines like this:
if(strcmp(M,"drawer")==0)
with this:
if (M == "drawer" )
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다