MFC 문자열 배열 상수(#define CString[]),#define 문자열

문자열을 배열을 상수 또는 전역변수로 선언하는 방법이 없을까?
문자열을 배열을 선언하는 방법은

CString mArr[]={"One","Two","a","b","c","1","2"};
CString mArr[5];
mArr[0]="One";
mArr[1]="Two";
mArr[2]="a";
mArr[3]="b";
...........

와 같이 주로 사용한다.
이부분을
#Define StringArray{“One”,”Two”,”a”,”b”,”c”,”1″,”2″} 과 같이 선언해놓고(//문자열배열로 선언, 실제동작하지 않음)
printf(StringArray[2]);//결과과 “a” 를 출력할 수 있도록 할 수 있을까?
구글링 해봐도 마음에 드는 해법이 보이지 않는다.
나의 경우는 StringArray를 전역으로 사용하기 위해 꼭 Define을 사용해야 할 필요가 있어서 고민을 해봤다!
결과는 대만족이다.  앞으로 이렇게 사용하는 방법도 권장할 만하겠다.
stdafx.h 파일에 이렇게 선언해 놓는다.

typedef struct _STRING_ARRAY:public CStringArray
{
	_STRING_ARRAY(LPCTSTR strtv, ... )
	{
		va_list vl;
		va_start( vl, strtv );
		while ( strtv )
		{
			Add(strtv);
			strtv = va_arg( vl, LPCTSTR );
		}
	    va_end(vl);
	}
}STRING_ARRAY;
#define AxisName STRING_ARRAY("A","B","X","Y","Z",0)

STRING_ARRAY Structure를 CStringArray로 부터 상속을 시켯다,  자신이 원하는대로 코딩을 하면 되지만
나의경우는 연산자 상속및 GetSize() 등등 다른 기능도 필요하므로 CStringArray로 부터 상속을 시켜서 편리하게 사용할 목적으로 만들었다.
_STRING_ARRAY(LPCTSTR strtv, … )와 같이  생성자를 만들고 실제 사용하는 부분에서 마지막 인자에 0을 넣었다는 것에 유의 하자
va_arg로 인자를 계속 검색 할 때 NULL=0를 만나야 종료되기 때문에 이렇게 처리했다.

“MFC 문자열 배열 상수(#define CString[]),#define 문자열”의 42개의 댓글

  1. I’m pretty pleased to find this site. I wanted to thank you for your time due to this wonderful read!!
    I definitely appreciated every little bit of it and i also have you saved to fav to look at new information on your website.

  2. Howdy I am so glad I found your blog page, I really found you
    by accident, while I was browsing on Askjeeve for something else,
    Regardless I am here now and would just like to say kudos for
    a fantastic post and a all round exciting blog (I also love
    the theme/design), I don’t have time to go through it all at the minute but
    I have saved it and also included your RSS feeds, so when I have
    time I will be back to read more, Please do keep up the awesome work.

  3. I just want to tell you that I am newbie to weblog and absolutely liked your blog. Almost certainly I’m planning to bookmark your blog . You absolutely have awesome article content. Appreciate it for sharing your blog site.

  4. My spouse and I stumbled over here by a different web address and thought I might check things out. I like what I see so i am just following you. Look forward to checking out your web page again.

  5. I know this if off topic but I’m looking into starting my own weblog and was curious what all is needed to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very internet savvy so I’m not 100 positive. Any tips or advice would be greatly appreciated. Kudos

  6. There are absolutely a great deal of information like that to consider. That is a wonderful indicate bring up. I provide the ideas above as basic inspiration however plainly there are questions like the one you bring up where the most important point will certainly be working in straightforward good faith. I don?t know if ideal methods have actually emerged around points like that, however I make certain that your work is clearly recognized as an up for grabs. Both kids as well as girls feel the impact of just a moment?s pleasure, for the remainder of their lives.

  7. A remarkable share, I just offered this onto an associate that was doing a little evaluation on this. And also he in fact got me breakfast since I located it for him. smile. So let me rephrase that: Thnx for the reward! Yet yeah Thnkx for spending the time to review this, I feel strongly concerning it and also like learning more on this subject. Preferably, as you become proficiency, would you mind updating your blog with more details? It is very helpful for me. Large thumb up for this blog post!

  8. There are some fascinating moments in this short article however I don?t understand if I see all of them facility to heart. There is some credibility however I will take hold point of view up until I check into it better. Excellent post, thanks as well as we want more! Included in FeedBurner also

  9. Great post. I was checking continuously this weblog and I am
    inspired! Very useful information particularly the closing section :
    ) I deal with such info much. I was looking for this certain info for a long time.
    Thanks and best of luck.

  10. Youre so trendy! I do not mean Ive read anything such as this prior to. So nice to locate someone with some original thoughts on this subject. realy thanks for starting this up. this site is something that is needed on the web, somebody with a little originality. helpful job for bringing something brand-new to the internet!

  11. I?m pleased, I have to say. Really seldom do I come across a blog that?s both informative as well as amusing, as well as let me tell you, you have struck the nail on the head. Your idea is exceptional; the issue is something that insufficient people are speaking intelligently about. I am very satisfied that I came across this in my look for something connecting to this.

  12. I was very happy to locate this web-site. I wished to many thanks for your time for this terrific read!! I certainly delighting in every little of it as well as I have you bookmarked to check out new stuff you article.

  13. Hi! I simply wish to give a significant thumbs up for the excellent information you have right here on this post. I will certainly be coming back to your blog for even more soon.

  14. The next time I read a blog, I really hope that it doesn’t dissatisfy me as long as this. I suggest, I understand it was my selection to read, yet I in fact assumed youd have something intriguing to say. All I hear is a lot of whimpering concerning something that you might fix if you werent too hectic looking for attention.

  15. naturally like your web site however you need to check the spelling on several of your
    posts. Many of them are rife with spelling problems and I find it very troublesome to tell the reality then again I’ll certainly come back again.

  16. This is the appropriate blog for anybody who intends to discover this topic. You recognize a lot its virtually hard to say with you (not that I actually would want?HaHa). You definitely placed a brand-new spin on a subject thats been discussed for several years. Excellent things, simply great!

  17. I?d need to get in touch with you below. Which is not something I typically do! I delight in reviewing an article that will make people think. Also, many thanks for enabling me to comment!

  18. After research a few of the article on your site currently, and also I really like your way of blogging. I bookmarked it to my bookmark internet site listing and will be inspecting back quickly. Pls take a look at my website too and let me know what you assume.

댓글 남기기