String problems

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
JerryTheBig
Posts: 33
Joined: July 27th, 2012, 12:48 pm

String problems

Post by JerryTheBig » July 17th, 2013, 9:10 pm

Hi
I have a big problem with string things
Firstly, I am not able to load a few pics to an array because this thing:

Code: Select all

array[i].SetSurface( std::wstring(L"Sprites\\temple\\t%d.bmp",i),D3DCOLOR_XRGB(255, 0, 255));
hates me, It is in the code. Please help me.
Secondly, could anybody tell me something about strings in c++. I am absolutely lost.
In c# I used only string s = "sth"; and that was all everything was string. (Perfect method ToString() made everything easier). And now. Somethimes I saw char something[]. Thats ok. Just an array of characters. But the work with it is horrible for me. In Jesse Liberty's book anout c++ is written that printf is horible thing. Better use cout<<.
Chili use a my nightmare above. I am not able to load a single sprite using wstring with parameters like %d,%char and put variable i after them.
Everything is in the code.
If you suggest better way. Ok but I want to know why it does not work and if is there some magic quide or somtehing about this problem then send me a reference.
Thanks a lot
Attachments
Platformer.rar
(663.25 KiB) Downloaded 128 times

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: String problems

Post by LuX » July 17th, 2013, 10:00 pm

Works for me anyway. Dunno, I'm used to use WCHAR* instead of going always for the std lib. Never liked sexually transmitted diseases anyway.
ʕ •ᴥ•ʔ

Nek
Posts: 10
Joined: July 11th, 2013, 3:55 pm

Re: String problems

Post by Nek » July 18th, 2013, 12:49 am

LuX wrote:Works for me anyway. Dunno, I'm used to use WCHAR* instead of going always for the std lib. Never liked sexually transmitted diseases anyway.
oh good, i'm not the only one that thinks of this when i type it in.

JerryTheBig
Posts: 33
Joined: July 27th, 2012, 12:48 pm

Re: String problems

Post by JerryTheBig » July 18th, 2013, 7:21 am

Can you help me solve this problem using wchar*? I am stuck. I cant continue without loading images

User avatar
joelyboy94
Posts: 67
Joined: October 11th, 2012, 7:34 pm

Re: String problems

Post by joelyboy94 » July 18th, 2013, 10:08 am

Most things you do with character arrays can be done with wide strings. For formatting strings you can use

Code: Select all

  
wchar_t a[100];
swprintf( a,100, L"image name = %s,image number = %d",L"harry",12);
Just use L in front of a string to declare it a a wide string.

See here http://www.cplusplus.com/reference/cstdlib/ for the conversion functions (Multibyte strings section)
See here http://www.cplusplus.com/reference/cwchar/ for standard wide string functions.

Hope that helps.

JerryTheBig
Posts: 33
Joined: July 27th, 2012, 12:48 pm

Re: String problems

Post by JerryTheBig » July 18th, 2013, 12:30 pm

Thanks a lot. It works.

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: String problems

Post by LuX » July 18th, 2013, 4:53 pm

joelyboy94 wrote:

Code: Select all

  
wchar_t a[100];
swprintf( a,100, L"image name = %s,image number = %d",L"harry",12);
Yes, but I think swprintf will give some warnings, not the end of the world, but it should be safer to use swprintf_s, which is the same but you don't have to input the array size.
ʕ •ᴥ•ʔ

User avatar
joelyboy94
Posts: 67
Joined: October 11th, 2012, 7:34 pm

Re: String problems

Post by joelyboy94 » July 18th, 2013, 5:04 pm

Yeah good point, that's something I've been meaning to do for while, but I've just been doing compiler warning disables for those.. not good I know haha.

Post Reply