The following example is taken from the help site and converted to c++.
It was just a quick thing I ported for example. More thought should go into what you want to do.
But it compiled and ran and did what it was supposed to do. just keep in mind it just useless example code.
Honestly I've been utilitizing AGK's uString class for strings so when I call a function that returns a char*. I basically
use a temp string used to hold the returned char* and then save that to a uString object. I believe the uString allocates its own memory
and copies the contents to a new char* internal and when the uString object goes out of scope it automatically de-allocates the memory used.
Once the returns char* is save to the uString object I call agk:
eleteString(tmpstr) to de-allocate the memory the library allocates.
char* example:
// Includes
#include "template.h"
// Namespace
using namespace AGK;
app App;
char* word;
void app::Begin(void)
{
agk::SetVirtualResolution (1024, 768);
agk::SetClearColor( 151,170,204 ); // light blue
agk::SetSyncRate(60,0);
agk::SetScissor(0,0,0,0);
char* text = "AGK,Example:Text";
word = agk::GetStringToken(text, ",:", 2);
agk::ResetTimer();
}
int app::Loop (void)
{
if (agk::Timer() > 5) return 1;
agk::Print( agk::ScreenFPS() );
agk::Print("Word (token) number to is: ");
agk::Print(word);
agk::Sync();
return 0; // return 1 to close app
}
void app::End (void)
{
agk::DeleteString(word);
//delete[] word;
}
uString Example.
// Includes
#include "template.h"
// Namespace
using namespace AGK;
app App;
uString word;
void app::Begin(void)
{
agk::SetVirtualResolution (1024, 768);
agk::SetClearColor( 151,170,204 ); // light blue
agk::SetSyncRate(60,0);
agk::SetScissor(0,0,0,0);
uString text = "AGK,Example:Text";
char* tmp;
tmp = agk::GetStringToken(text, ",:", 2);
word = tmp;
agk::DeleteString(tmp);
agk::ResetTimer();
}
int app::Loop (void)
{
if (agk::Timer() > 5) return 1;
agk::Print( agk::ScreenFPS() );
agk::Print("Word (token) number to is: ");
agk::Print(word);
agk::Sync();
return 0; // return 1 to close app
}
void app::End (void)
{
}