Can someone help me debug my program?

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <iterator>
#include "MQmessage.h"
#include "xmlrB2BMQClass.h"

using namespace std;
int main(void)
{
// declaring an array to store name/value pair
struct Property user_property[2];
xmlrB2BMQClass xmlrMQresponse;
xmlrMQresponse.SetMQStateCode("Ajit");
xmlrMQresponse.SetMQErrorCode("Gunge");
const char* const list1[] = {"stateCode","errorCode"};
user_property[0].value=(const char*)GetMQStateCode();
//const char* const list2[] = {xmlrMQresponse.GetMQStateCode(),xmlrB2BMQClass.GetMQStateCode()};
const size_t len = sizeof(list1) / sizeof(list1[0]);
for (size_t i = 0; i <len; i++) {
strcpy(user_property[i].name,list1[i]);
// strcpy(user_property[i].value,list2[i]);
}
for (size_t i = 0; i <len; i++) {
cout <<user_property[i].name<<endl;
cout <<user_property[i].value<<endl;
}
return 0;
}
The compile error is at line 18 GetMQStateCode not declared in this scope.What is that I am doing wrong here.
Last edited on
//const char* const list2[] = {xmlrMQresponse.GetMQStateCode(),(xmlrB2BMQClass.GetMQStateCode()};

You opened a ( here. I don't know if this is going to fix the error, but the syntax is wrong.
yeah.That was an error but the actual problem is something different.I have a getfunction that returns a string I want to store the values of these get fucnitons in character arrays.Is there a way that I can do this.If yes can someone tell me how?
First, please use code tags - the <> button on the right.

The compile error is at line 18 GetMQStateCode not declared in this scope.


You are probably missing a header file.

HTH
I assume

user_property[0].value=(const char*)GetMQStateCode();

is the error. according to the line below it must be:

user_property[0].value=(const char*)xmlrMQresponse.GetMQStateCode();
[EDIT] do not cast a string to const char*. it's invalid!

I have a getfunction that returns a string I want to store the values of these get fucnitons in character arrays
Why do you want to do so? string is much more convenient.

Use c_str() to achieve that:

http://www.cplusplus.com/reference/string/string/c_str/

But be careful! if the string object doesn't exist any more the pointer is invalid as well
Last edited on
Topic archived. No new replies allowed.