为什么我不能在立即窗口中索引 std::vector ?
所以,我有一个向量,
std::vector<std::string> lines.
我填充了这个向量,并且可以像这样访问它
std::string temp = lines[0];
但是,在立即窗口中,
lines[0] - error:overloaded operator not found
和
lines.at(0) - error:symbol is ambiguous
根本不起作用。在 c++ 中使用立即窗口是否有技巧?我主要来自 C# 背景,一切都运行良好(并且我在立即窗口中有智能感知)。我没想到 C++ 会很棒,但我认为它也适用于除整数之外的其他事物。谁能告诉我我做错了什么?谢谢。
编辑:我应该清楚,在立即窗口中没有任何东西真正起作用,这只是一个简化的示例
编辑:我处于调试模式
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
立即窗口和监视窗口不支持重载运算符。其中有一些支持以合理的方式打印整个标准容器(例如,参见 http://www.virtualdub.org/blog/pivot/entry.php?id=120),但这并不意味着能够使用
operator[]< /代码> 他们。
希望这会在调试器的后续版本中得到改进,但现在,要查看向量的第 i 个元素,请尝试
lines._Myfirst[i]
。(
_Myfirst
,在VC++自带的标准库中,恰好是std::vector
中的成员变量,指向序列的第一个元素。所以这个只是检查一个向量,就好像它是任何其他对象一样。要解决这个问题,我必须查看标头......不太方便,但希望这会对您有所帮助。但你必须查看标头才能弄清楚如何操作。)(顺便说一句,如果你一直在使用 C# 工作,那么相比之下,C++ 调试器总体上可能显得不太流畅,这只是其中之一我的印象是 CLR 方面投入了更多的工作。)
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 astd::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.)
在现在的 Visual Studio 版本(例如 2013/2015)中,std::vector 变量不再存在 _Myfirst 成员变量。使用 _C_begin 代替 - 意味着给定的示例使用lines._C_begin[i]。
In nowaday's Visual Studio versions (e.g. 2013/2015) _Myfirst member variable does no longer exist for a std::vector variable. Use _C_begin instead - means for the given example use e.g. lines._C_begin[i].