MSVC 2005 question

I just got MSVC 2005, and I'm having some problems.

I ran the following test:
#include <iostream>
#include <string>

int main(int argc, char *argv[])
{
      int i;
      std::string s;

      std::cout << "Enter in a string: " << std::flush;
      std::getline(std::cin,s);
      i = s.length();

      std::cout << "You entered: " << s;
      std::cout << " which is " << i << " characters long" << std::endl;
      return 0;
}

Simple program which compiles and runs just fine.  The problem is when I run it in the debugger.  If I input in the string "hello there", the debugger variable watch shows the string as having the value: "€PD"  
Also, the variable i doesn't show up on the variable watch at all.  The only variables which show up are argc, argv, and s.  

Anyone have any insight here?
LVL 5
lwinkenbAsked:
Who is Participating?
 
CetusMODCommented:
PAQed with points refunded (250)

CetusMOD
Community Support Moderator
0
 
rajeev_devinCommented:
There is some bug with the compiler.
It should work fine.
0
 
lwinkenbAuthor Commented:
Is it possible I have a project setting that is off?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rajeev_devinCommented:
>> Is it possible I have a project setting that is off?
Are you using the free trial version of MSVC 2005 ?
Then this is obvious.
0
 
AlexFMCommented:
Click on the + sign near string variable in the Watch window. One of string members is char* pointer which must show right value.
0
 
lwinkenbAuthor Commented:
>> Are you using the free trial version of MSVC 2005 ?
I don't think so.  I'm using a version I got through my school.

>> Click on the + sign near string variable in the Watch window. One of string members is char* pointer which must show right value.
Strangely enough, there is no + sign.  It acts as if string is a primitive type that doesn't have any members.
0
 
lwinkenbAuthor Commented:
Here is some more information.  When I run the following:

int main(int argc, char *argv[])
{
      char str[] = "hello there my friend";

      std::cout << str << std::endl;
      return 0;
}

The debugger shows str as the following:  -            str      0x0012ff38 "œùŸhellHÿ"      char [22]
str[0]   -100
str[1]   -7
str[2]   -97
str[3]   7
str[4]   104
str[5]   101
str[6]   108
str[7]   108
str[8]   72
str[9]   -1
str[10]  18
str[11]  0
str[12]  122
str[13]  -79
str[14]  65
str[15]  0
str[16]  109
str[17]  121
str[18]  32
str[19]  102
str[20]  -68
str[21]  -84

The debugger is clearly having problems.  Is it possible that I have a bad installation?  The debugger works just fine with C# applications.
0
 
lwinkenbAuthor Commented:
Well, I figured out the problem finally.  When I turn off the compiler optimization /02, then everything works fine.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.