Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 15, 2004 constructing char[] variables | ||||
---|---|---|---|---|
| ||||
Give the following:
char[] str;
for(int i = 0; i < 50; i++)
str ~= "*";
is there another way to accomplish this in D?
In C++ I would simply:
std::string str(50, '*');
TIA,
Andrew
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
|
March 15, 2004 Re: constructing char[] variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Edwards | You can do it this way as well although it is probably more hassle: char[] another ; for(int i = 0; i < 50; i++) { another.length = i + 1; strcat(another, "*"); } You would need to : import std.string; Phill. "Andrew Edwards" <remove_ridimz@remove_yahoo.com> wrote in message news:opr4v5dnvus6zaqn@news.digitalmars.com... > Give the following: > > char[] str; > for(int i = 0; i < 50; i++) > str ~= "*"; > > is there another way to accomplish this in D? > In C++ I would simply: > > std::string str(50, '*'); > > TIA, > Andrew > -- > Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ |
March 15, 2004 Re: constructing char[] variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Edwards | Andrew Edwards wrote: > Give the following: > > char[] str; > for(int i = 0; i < 50; i++) > str ~= "*"; > > is there another way to accomplish this in D? > In C++ I would simply: > > std::string str(50, '*'); > > TIA, > Andrew char[] str = new char[50]; str[] = '*'; -- Christopher E. Miller |
March 15, 2004 Re: constructing char[] variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Edwards | Andrew Edwards wrote: > Give the following: > > char[] str; > for(int i = 0; i < 50; i++) > str ~= "*"; > > Just a small quibble with this code: char[] str; str.length = 50; //Initialize size first foreach(inout char c; str) c = '*'; > is there another way to accomplish this in D? > In C++ I would simply: > > std::string str(50, '*'); Make your own function to do this. -- -Anderson: http://badmama.com.au/~anderson/ |
Copyright © 1999-2021 by the D Language Foundation