SetName (C++)


#1

How I can set the name of node with this pattern? note that i and j are inetger

node->SetName(_T("Bone"+i+j));


#2

if you want to keep it all “max”

Then something like

TSTR name;
name.printf(_T("Bone%d%d"),i,j);
node->SetName(name.data());

would be as good as any (note i’ve typed that off the top of my head so may or may not work :slight_smile: )
but otherwise lots of “standard” c/cpp ways of doing it.


#3

Actually I was looking and prefer CPP method…


#4
typedef std::basic_string<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR>> tstr;

tstr name = _T("Bone");
TCHAR temp[21];
name += _itot(i,temp,10);
name += _itot(j,temp,10);
node->SetName(name.c_str());

or something like

typedef std::basic_stringstream<TCHAR, std::char_traits<TCHAR>, std::allocator<TCHAR>> tstream;

tstream bonestrm;
bonestrm << _T("Bone") << i << j;
 node->SetName(bonestrm.str().c_str());

#5

Thank You!, but I think your first method is simpler.


#6

i would do something like:


// where : MSTR base, int x, int y

std::wstringstream wss;
wss << std::wstring(base) << x << y;
MSTR name = wss.str().c_str();

if i want to do it more c++ than max sdk.

anyway it would be very close to what Klvnk showed.