-2

I have a problem when using string.

This is my C++ code:

string s;
s = "..\inputs\Meknes_ext1\REF_WV02_12SEP15_ext1";

The compilation was successfully done, but when debugging, the string s takes random values like "hûJ" at the first line and then the affectation don't change his content.

How can I resolve this error?

msrd0
  • 7,816
  • 9
  • 47
  • 82
user2987264
  • 7
  • 1
  • 1
  • 5
  • 4
    It's possible it's escaping the character (\n for example is a new line), replace \ with \\. – Borgleader Oct 22 '14 at 16:57
  • `The compilation was successfully done,` There were no warnings about using illegal escape sequences? – PaulMcKenzie Oct 22 '14 at 17:24
  • no warning in compilation, and the problem still the same when I replace \ with \\ and even when I put any other string like s = "hello world" it takes only 'o world' – user2987264 Oct 22 '14 at 19:57

3 Answers3

1

You need to escape the escape character \, change this to \\:

s = "..\\inputs\\Meknes_ext1\\REF_WV02_12SEP15_ext1";
msrd0
  • 7,816
  • 9
  • 47
  • 82
  • the problem still the same when I replace \ with \\ and even when I put any other string like s = "hello world" it takes only 'o world'. seems that the problem come from the declaration when a rondom value is attributed to the string and i don't know why – user2987264 Oct 22 '14 at 19:58
1

you need to escape the \ special character. Your string must be like that:

s = "..\\inputs\\Meknes_ext1\\REF_WV02_12SEP15_ext1";
Ludovic Feltz
  • 11,416
  • 4
  • 47
  • 63
  • the problem still the same when I replace \ with \\ and even when I put any other string like s = "hello world" it takes only 'o world'. seems that the problem come from the declaration when a rondom value is attributed to the string and i don't know why – user2987264 Oct 22 '14 at 20:01
  • random values seen at the add watch – user2987264 Oct 23 '14 at 15:47
0

I find out that this problem occur only when debugging, in the execution, the string takes the right value, note that I'm using the RelWithDebInfo mode. the explanation of this was find in: Visual Studio: Garbled debug watch of std::string's?

Community
  • 1
  • 1
user2987264
  • 7
  • 1
  • 1
  • 5