I have an xml file that I have to read in, convert all the carriage returns to \x0D and line feeds to \0xA, then call it into a function as a string.

So for example my XML file is:

<TEST>
this is a string
</Test>

I would want a string that contains "<TEST>\x0D\0xAthis is a string\x0D\x0A</Test>"

I've been able to read the XML file with pugiXML but I have not been sucessful in converting it to a string or finding the carriage returns/line feeds. ANy help would be appriciated. Thanks.

Solution Found. I found out how to solve my own problem, but here's an update in case someone else needs to see this.

std::ifstream ifs(skp_filename.c_str());
  std::string content( (std::istreambuf_iterator<char>(ifs) ),
                       (std::istreambuf_iterator<char>()    ) );

   size_t pos = 0;
  while((pos = content.find("\n", pos)) != std::string::npos)
  {
     content.replace(pos, 2, "\\x0D\\x0A");
     pos += 8;
  }

With this code, I read in my XML file, find all references to \n and relace it with \x0D\x0A.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.