Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4095724
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:56:15+00:00 2026-05-20T19:56:15+00:00

as per the class reference the TixmlText takes const char* values as input. i

  • 0

as per the class reference the TixmlText takes const char* values as input.
i need to store integer data read from a text file into xml. the integer data is stored in int vector and each element of the vector is converted to const char* before passing it to Tixml text function.

const char* intToXmlChar(int num)
{
    stringstream abc;
    string value;
    abc<<num;
    value=abc.str();
    const char* ret_val = value.c_str();
    //char* conv_val = const_cast<char*>(ret_val);
    return ret_val;
}

But when i finally see the generated xml document. i get garbage values in the element where i save the number

<timestamp>1&#x00;504</timestamp>

how do we store integer data properly?

i had traced the where the problem was happening to an extent in the tinyxml.h

class TiXmlNode : public TiXmlBase

the function

void SetValue(const char * _value) {
printf(" pre ---number--- %s  using this \n",_value); //-- if the value is say 18504
 value = _value;
printf(" post ---number--- %s  using this \n",_value); //-- becomes 1&#x00;504 saved in xml
    }

where the value is of the same class TiXmlNode
being TIXML_STRING value;

  • Question: Am i missing some thing
    very simple?
  • Question: How can i
    store the integer data properly

Edit:
Thanks for the answers
from the docs a point which i missed
Use the compile time define:

TIXML_USE_STL

to compile one version or the other.
This can be passed by the compiler, or
set as the first line of “tinyxml.h”.

Note: If compiling the test code in
Linux, setting the environment
variable TINYXML_USE_STL=YES/NO will
control STL compilation. In the
Windows project file, STL and non STL
targets are provided. In your project,
It’s probably easiest to add the line
“#define TIXML_USE_STL” as the first
line of tinyxml.h.

Tinyxml class ref

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:56:16+00:00Added an answer on May 20, 2026 at 7:56 pm

    If you’re compiling TinyXML with STL support (which you probably should be) TiXmlText also has a std::string constructor. As sekmet64 says, the memory allocated by the std::string for c_str() is released when the function exits so you are, in effect, returning a pointer to garbage.

    However, I would strongly recommend against allocating your own memory. Instead, return a std::string (which will take care of the memory for you):

    std::string intToXmlChar(int num)
    {
        std::stringstream abc;
        std::string value;
        abc<<num;
        return abc.str();
    }
    

    and then pass this into the TiXmlText constructor either as

    TiXmlText node(intToXmlChar(i));
    

    or as

    TiXmlText node(intToXmlChar(i).c_str());
    

    the latter case is ok because TiXmlText will take a copy of the temporary string before it is destroyed.

    In general stay away from conversion to a char* unless (or until) absolutely necessary, std::string is a safer and superior option the vast majority of the time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have some per-class data: (AandB.h) class A { public: static Persister* getPersister();
I come from a background where I normally create one file per class. I
I'm used to the Java model where you can have one public class per
To what is the class path of a Servlet container set? As per my
Per man pages, snprintf is returning number of bytes written from glibc version 2.2
Per http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html The init method of NSDateFormatter is Available in iPhone OS 2.0 through
Per my other post about WCF service return values , I'm consuming a web
It seems that in November, Apple updated both the NSManagedObjectContext Class Reference and the
I have three classes mapped using the table-per-subclass class mapping strategy. The tables are:
Suppose I have a Singleton class (any class can get the instance): class data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.