-5

To make it short, here is the code :

std::string m_specs = "f500000";
float m_sten = 21.0;
std::cout << m_specs << std::endl;
m_specs = "f" + boost::lexical_cast<std::string>(m_sten);
std::cout << m_specs << std::endl;

The first output will be :

f500000

, but the second will be

f6.70932579e+028

The expect result is

f21.0

I don't have any idea why is this conversion so strange... I need your lights. Thank you in advance.

Marion
  • 13
  • 1
  • 5
  • 2
    In the first line, you use `m_sten` but in the 3rd line, you use `m_stren`. Also, why are you lexical casting a string to a string? What are you trying to do? Are you sure you're doing it right? – Mahmoud Al-Qudsi Jan 26 '15 at 21:29
  • Edited, sorry, this isn't it. – Marion Jan 27 '15 at 05:21
  • [ideone](http://ideone.com/etRdIb) disagrees with you. How about a complete example? – Retired Ninja Jan 27 '15 at 05:42
  • Voting to close as we've now gotten two defective code snippets which fail to repro the issue. OP, please get the issue to actually occur in code you can post without alteration. (Use ideone!) – StilesCrisis Jan 27 '15 at 15:21

2 Answers2

2

Your code switches between m_stren and m_sten.

Are you sure you're not mixing up two different but similarly named variables?

StilesCrisis
  • 15,972
  • 4
  • 39
  • 62
  • Oh, sorry, when I post something, I always make the code shorter and forgot some little things, I'll edit the code fast, this isn't a varame problem, I just make mistake in the code on SOF. Sorry. – Marion Jan 27 '15 at 05:20
-1

Well, I found out the solution, in fact, m_sten wasn't really declared. I forgot to declared it by a function. Thank for having attention on this.

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
Marion
  • 13
  • 1
  • 5