View unanswered posts | View active topics It is currently Wed Jan 16, 2019 10:44 am



Reply to topic  [ 5 posts ] 
 String functions in C++ 
Author Message

Joined: Sat Nov 21, 2009 7:55 pm
Posts: 6
The string variable type isn't included in the NDS library. I don't know whether the DS supports it. Anyway, all the examples I've seen use Char arrays instead. Anyway, I'm trying to make a function where a string is output, but I can't work out how to do it.

Can anyone help?

Thanks.


Thu Dec 03, 2009 7:52 pm
Profile
User avatar

Joined: Fri Jul 11, 2008 8:49 pm
Posts: 222
Location: The Netherlands
all c++ libraries are supported, but most of them should be avoided because they are bloated.

anyway, this works for me:

Code:
#include <cstdio>
#include <string>

#include <nds.h>

int main()
{
   consoleDemoInit();

   const char* test = "this is a test";
   std::string test2 = "\nthis to is a test";

   iprintf(test);
   iprintf(test2.c_str());

   while(true)
   {
      swiWaitForVBlank();
   }

   return 0;
}

_________________
my blog:
http://vuurrobin.100webcustomers.com/


Thu Dec 03, 2009 8:20 pm
Profile WWW

Joined: Sat Nov 14, 2009 1:41 am
Posts: 23
sprintf :D to change the char array :D. Hope it helps, any way, as I used it, I had to set the lenght at the begining, but it's posible to change the lenght during execution:


char sText[30] = "Hola";

...

sprintf(sText, "Text");

...

You can also write variables in it:

char sText1[30] = "Hola";
char sText[30] = "";
...
sprintf(sText, "%s %d", sText1, 10);
...

And to change its size just read about the malloc function.

Hope it helps, regards.


Fri Dec 04, 2009 4:54 pm
Profile

Joined: Sat Nov 21, 2009 7:55 pm
Posts: 6
Thanks for the responses. '#include <cstdio>' and '#include <string>' cause errors. I'll try the other example.


Tue Dec 08, 2009 12:52 am
Profile
User avatar

Joined: Fri Jul 11, 2008 8:49 pm
Posts: 222
Location: The Netherlands
make sure you named the extention .cpp and not .c

_________________
my blog:
http://vuurrobin.100webcustomers.com/


Tue Dec 08, 2009 9:04 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.
Get devkitPro at SourceForge.net. Fast, secure and Free Open Source software downloads