views:

356

answers:

2

So, I have a vector

 std::vector<std::string> lines. 

I fill this vector up, and can access it like

 std::string temp = lines[0];

However, in the immediate window, both

 lines[0] - error:overloaded operator not found

and

 lines.at(0) - error:symbol is ambiguous

don't work at all. Is there a trick to using the immediate window with c++. I'm mostly coming from a C# background, where everything works nicely (and I have intellisense in the Immediate Window). I wasn't expecting C++ to be great, but I figured it would work for things besides ints. Can anyone tell me what I'm doing wrong? Thanks.

EDIT: I should be clear, nothing really works in the immediate window, this is just a simplified example

EDIT: I'm in debug mode

A: 

The most common reason of such a behavior in immediate window is that you try to debug c++ code in release environment. Switch do debug and it will start working.

alemjerus
Hi, I'm already in debug mode
Steve
Do you have intellisense in your immediate window?
Steve
I don't get intellisense in the immediate window for native code; I think it's a native code debugger limitation.
brone
+4  A: 

The immediate and watch windows don't support overloaded operators. There is some support in there for printing standard containers as a whole in a sensible fashion (see, e.g., http://www.virtualdub.org/blog/pivot/entry.php?id=120), but this doesn't extend to being able to use operator[] on them.

Hopefully this will be improved in later revisions of the debugger, but for now, to look at the i'th element of a vector, try lines._Myfirst[i].

(_Myfirst, in the standard libraries that come with VC++, happens to be the member variable in a std::vector that points to the first element of the sequence. So this is just examining a vector as if it were any other object. To work this out, I had to look at the headers... not very convenient, but hopefully this will help you. You can probably do something similar with the other containers, but you'll have to look in the headers to work out how.)

(By the way, if you've been working in C#, the C++ debugger will probably seem by comparison a bit less slick in general, and this is just one example of that. I get the impression there's been much more work put into the CLR side.)

brone
OK, thanks for the help on that, buy why would .at() fail?
Steve
Calling member functions in the watch and immediate windows just doesn't seem to work either. (I've updated my answer to mention the lack of slickness -- this is a 2nd example!) You can usually call freestanding functions though. Annoying, but you can get used to it -- not that you have any choice of course :) (Hopefully later revisions will improve the native debugging side; it's already perfectly serviceable, but just lacks the polish that the CLR side has.)
brone
.at() probably fails for the same reason: it's overloaded.
MSalters