View previous topic :: View next topic |
Author |
Message |
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Tue Dec 11, 2007 9:01 am Post subject: SDL_GetError() problem |
|
|
Hello,
I am having some trouble understanding how to concatinate SDL_GetError()'s return with my own string.
if I do something like this:
Code: | log("Unable to init SDL: " ~ SDL_GetError());
//where log() is:
void log(char[] msg)
{
File f = new File("log.txt", FileMode.Out);
f.writeLine(msg);
f.close();
} |
When building I get:
main.d(53): Error: Can only concatenate arrays, not (char* ~ char*)
main.d(53): function main.log (char[]) does not match parameter types (int)
main.d(53): Error: cannot implicitly convert expression ("Unable to init SDL: "
~ (*SDL_GetError)()) of type int to char[]
If someone knows what I am doing wrong, please explain it to me as I am interested in understanding how concatenation and strings work in D. I have read about it, but perhaps someone else can give further insight.
Thanks,
Zane _________________ わたしがプログラマだよ! |
|
Back to top |
|
|
doob
Joined: 06 Jan 2007 Posts: 367
|
Posted: Tue Dec 11, 2007 3:40 pm Post subject: |
|
|
You can only concatenate D strings, you are trying to concatenate C strings. Call the toString function in std.string for phobos or toString (former toUtf8, don't remember in what module) for tango to convert to a D string. |
|
Back to top |
|
|
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Tue Dec 11, 2007 4:34 pm Post subject: |
|
|
Thanks very much!
Argh, I can't believe I made such a stupid mistake .
Thanks again,
Zane _________________ わたしがプログラマだよ! |
|
Back to top |
|
|
|