Computing.Net > Forums > Programming > C++ Arrays (Simple Q)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++ Arrays (Simple Q)

Reply to Message Icon

Name: concentriq
Date: November 5, 2002 at 15:01:27 Pacific
OS: WinXP
CPU/Ram: 550/512
Comment:

im at a bit of a loss here. I never had to work with strings, so forgive me if it is trivial:
i want to have an array of strings in C++, for example:

string array[10];
array[0] = "I dont";
array[1] = "understand";

program compiles, but i cant cout any values from an array. any help is much appreciated



Sponsored Link
Ads by Google

Response Number 1
Name: Ronin
Date: November 5, 2002 at 16:25:22 Pacific
Reply:

What you're after here I think is

char *array[2] = { "help me", "I've fallen and I can't get up" };

cout [[ array[0]

should see help me

cout [[ array[1]

should see I've fallen and I can't get up

If you're after individual chars, then

array1[4] = { 'A', 'B', 'C', 'D' };

cout [[ array1[0];

shoud see the letter A

cout [[ array[3]

should see the letter D

That *should* work with the "string" variable as well, but I'm using an older compiler where "string" isn't defined as an array of characters. You might have to remove the * symbol before the array name when using string, but I'm not sure.

HTH


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++ Arrays (Simple Q)

C++ Array Pointer Parameter www.computing.net/answers/programming/c-array-pointer-parameter/6482.html

C++ array help needed www.computing.net/answers/programming/c-array-help-needed/5479.html

C - array of strings www.computing.net/answers/programming/c-array-of-strings/8401.html