Is it possible to declare something like

string blah[51]

The way I would assume this would function is that each elements of the blah array would be a string, or is this not possible?

Thanks

Edit: just tried this in dev c++, and it didn't give me any errors, but well it bite me in the ass later if i try to apply it?

ex: cout << blah[23];

console output: What ever characters i stored in 23rd slot.

Recommended Answers

All 5 Replies

Why don't you write a test program to check it?

sorry, i must have edited after you already posted, but i did. So i guess the real question is, well it cause problems down the road, or should it function how i would assume?

sorry, i must have edited after you already posted, but i did. So i guess the real question is, well it cause problems down the road, or should it function how i would assume?

I'm not sure what problems you are having. This worked fine for me.

#include <string>
#include <iostream>


int main ()
{
    std::string blah[51];
    
    blah[3] = "Sam";
    blah[23] = "Bob";
    
    std::cout << blah[23] << std::endl;
    std::cin.get ();
    return 0;
}

It displays "Bob", as it should. I'm not sure what you are assuming/would like it to do. I wasn't clear about what you meant by the 23rd character in your post. It should display the 23rd string (not character) in your array. Can you elaborate?

How about:

vector<string> blah;
string temp;

for(int i = 0; i < 52; i++)
{
    some_random_string_generating_function(temp);
    blah.push_back(temp);
}

cout << blah[23] << endl;

Thank you for your guys input, this question was for my general knowledge because it randomly popped into my head. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.