D - constructing char[] variables
- Andrew Edwards (11/11) Mar 14 2004 Give the following:
- Phill (13/24) Mar 15 2004 You can do it this way as well although
- Vathix (5/18) Mar 15 2004 char[] str = new char[50];
- J Anderson (9/16) Mar 15 2004 Just a small quibble with this code:
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/
Mar 14 2004
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/
Mar 15 2004
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, Andrewchar[] str = new char[50]; str[] = '*'; -- Christopher E. Miller
Mar 15 2004
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/
Mar 15 2004