Sign in to follow this  

std::string strArrayGatheredObjectData[16] rationalisation of c++ datatype!

This topic is 2636 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey there I am wondering why I would want EVER perform the method in the title of this section and want a string with a character array of 16?

It should be 16 strings if I wanted a character array I would have just gone char object[16].

This has really gotten on my nerves! It deviates from every other object you will ever make in whats its doing. If I make it a two dimensional array I have to manually assign every character and set an upper boundary on the size, thats rubish! I want to address an array of strings with a string going into the character array inside of it without manually changing each character myself.

I know a string is technically an array from the off but you dont expect to create an array of your own class and instead of making an array of your class type have one instance with an internal array set to the quantity you set the class to be! Internal objects of anything should never be handled externally without being a function of the objects constructor!

Pseudo code...
class bob()
{
int[5];
}

Then

bob myobject[50];

Is not going to change the size of the array inside bob giving you one copy of bob!

So why does this happen? and how do I painlessly make an array of string arrays I can treat properly. I googled it and get a load of garbage about creating an array of pointers to strings and using vectors. Give me a simple implementation of a vector that I can use to manage multiple strings (treated as a string not a character array (e.g stringArray[2] = string)) and I will be happy.

I apologise for my rant, but I am worried any rationalisation of this formatting is going to fall into question as being well, inherently inconsistent. Bring on the answers! :) I hope the answer doesn't involve standard data types being allowed to do whatever they want because there should be a rule for this sort of thing.

Share this post


Link to post
Share on other sites
I don't understand what you're asking.

This:

std::string strArrayGatheredObjectData[16];

is an array of 16 strings.

This:

bob myobject[50];

is an array of 50 objects of type bob. Each one contains an array of 5 ints.

Quote:
Give me a simple implementation of a vector that I can use to manage multiple strings


std::vector<std::string> vec;

Share this post


Link to post
Share on other sites
Quote:
Original post by EnlightenedOne
It should be 16 strings
It is.

strArrayGatheredObjectData[12] = "Hello World!";

for (int i = 0; i < 16; i++) {
// deliberate use of printf to show types
printf("%d: '%s'\n", i, strArrayGatheredObjectData[i].c_str());
}

Share this post


Link to post
Share on other sites
std::string strArrayGatheredObjectData[16];

Should be an array of 16 strings.

However as this shows it is evidently not.

string as character array :(

If I make intObjectToGather set another value I do not see it overwrite the content of the string shown here but I cannot visibly see the string in my debugger. I have not tired extracting it. I will see if its just the debugger not showing me whats actually held in the datatype.

Share this post


Link to post
Share on other sites
charGatherer == *";"

WTF?

Dat be some bad mojo in dere.

A char is declared as ';'.

Quote:
However as this shows it is evidently not.


It's showing contents of s[i], not s.

Share this post


Link to post
Share on other sites
I apologise all, I had been expecting a layout sort of like what you see for the integer array for the string, not to be shown a sub components details.

What I was expecting.

When I stepped through the code and the integer for the object I was looking at changed the string I saw did not change! You always see the first string! That threw me into thinking I had just created an array of characters... not an array of strings. Am I making sense now?

Share this post


Link to post
Share on other sites

This topic is 2636 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this