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.
String functions in C++
Re: String functions in C++
all c++ libraries are supported, but most of them should be avoided because they are bloated.
anyway, this works for me:
anyway, this works for me:
Code: Select all
#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;
}
Re: String functions in C++
sprintf to change the char array . 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.
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.
Re: String functions in C++
Thanks for the responses. '#include <cstdio>' and '#include <string>' cause errors. I'll try the other example.
Re: String functions in C++
make sure you named the extention .cpp and not .c
Who is online
Users browsing this forum: Google [Bot] and 0 guests