The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 array of string

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
mletzgus Posted - 10/31/2003 : 06:45:40 AM
Hi,


what's wrong here:

const string Units[5]={"psek", "nsek", "musek", "msek", "sek"};

printf("%s\n", Units[1]);

Output is just the '\n', no "nsek".


thx,
michael
4   L A T E S T    R E P L I E S    (Newest First)
mletzgus Posted - 11/01/2003 : 04:02:35 AM
hi all,

i'm "native" C/C++ coder - so I tried to keep code as clean and "C-like" as possible.

But the StringArrays/vectors work very well. Thanks :-)

by,
Michael
cpyang Posted - 10/31/2003 : 09:40:20 AM
Hi Mike,

in <string.h>

typedef vector<string> StringArray;

so they are the same thing. I prefer using vector<string> just to be more accurate.

CP




Edited by - cpyang on 10/31/2003 09:40:41 AM
Mike Buess Posted - 10/31/2003 : 09:16:55 AM
Hi CP,

StringArray seems to work.

const StringArray saUnits = {"psek", "nsek", "musek", "msek", "sek"};
printf("%s\n", saUnits[1]);
printf("size=%d\n",saUnits.GetSize());

Is there a reason not to use that?

Mike Buess
Origin WebRing Member
cpyang Posted - 10/31/2003 : 08:54:30 AM
It seems that there is a bug with string array initialization. We don't recommand using string in a C array as Origin C has vector which suports string and vector is more reliable, and has basic support like GetSize(),

Try this


const vector<string> Units={"psek", "nsek", "musek", "msek", "sek"};
printf("%s\n", Units[1]);
printf("3rd char is %c\n", Units[1][2]);



As for the array initialization bug, I have added a tracker 5457
CP




Edited by - cpyang on 10/31/2003 08:56:49 AM

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000