On my system that produces this (possibly surprising) result:
Before: Hello
After: Bye o
Also, it would probably behoove you to either post new information at the end of the thread so the thread is also bumped, or bump the thread drawing attention to the edit after you've made it to a previous post. Just editing a previous post in the thread will not bump it up any.
Thanks Cire. Sorry I am new to c++.
I am working on a project to form a cluster algorithm in Omnet++ and veins. Actually I have a struct which I have to copy to constant char* so that to pass it as a string. I am trying to do like this to setWsmData as a cstring in the below function "sendMessage" and to receive the sent value in getWsmData in the function "onData" :
File:- pedcluster.h
=============
class PedCluster:: public BaseWaveApplayer {
...
protected:
void sendMessage(std::string blockedRoadId) ;
struct cluster{
int clustNum;
std::string messageName;
....
};
}
Even if hello were not const, it points to some random place in memory. You cannot write to that random place with memcpy or by any other method and expect your program to do anything sensible. This is undefined behavior.
(And it looks like you have control over the type of hello so why make it a pointer-to-const since you want to modify what's pointed to? Why is blockedRoadId a parameter instead of a local variable as you never use the value passed into the function?)
Thank you Cire. Yeah I think this is where I am making mistake in these three lines.
Could you please suggest how to solve this, so that to pass the data of the cluster in setWsmData.