ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I don't have much time to explain, but take a look at the following; it will probably simplify your code:
Code:
#include <string>
#include <map>
using namespace std;
int main()
{
typedef basic_string<char> ComponentData;
map<int, ComponentData> dataRcvdFromComponent;
char receivedData[4011] = {0}; // data from your component; for now, all zeroes
size_t dataSize = 3456 + 16; // number of bytes received from the component; not sure where the 16 comes from?
dataRcvdFromComponent.insert(make_pair(0, ComponentData(receivedData, dataSize)));
// or the less efficient, but easier to read
dataRcvdFromComponent[0] = ComponentData(receivedData, dataSize);
}
--------------
EDIT:
Now that I have the time, what I wanted to indicate earlier is that the "value" type of your STL map needs to be copyable, and that a char array does not offer that feature. In other words, in regular C or C++, this would not work:
Code:
char a[4111];
char b[4111];
b = a; // error: ISO C++ forbids assignment of arrays
P.S. If your component data is a collection of unsigned bytes, then use "unsigned char" in lieu of "char" above; or better yet, use "uint8_t".
Last edited by dwhitney67; 03-02-2011 at 07:07 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.