C++ 的智能感知在VS2010中
所有,
我对 C++ 项目的 Intellisense 有一个奇怪的问题。背景:我最近安装了 VS2010 Sp1,但 SQL Server 2008 R2 的 Intellisense 丢失了。我尝试按照建议安装累积更新 7 (CU7),但这不起作用。然而,重新安装 SQL Server 2008 R2 就可以了。然后我使用 SQL Server 2008 R2 的 CU7 进行更新,一切都很好。现在 Intellisense 对于 C# 项目工作得很好,但现在对于 C++ 项目却不能正常工作(注意:C++ 项目不是 C++/CLI)。
我已禁用预编译标头(“不使用预编译标头”)并具有以下内容:
#include <cmath>
#include <complex>
#include <iostream>
#include "stdafx.h"
#include "globals.h"
using namespace std;
注意:我知道使用 std 命名空间并不总是被认为是最佳实践,但在这里它将节省我的时间并且没有机会的歧义。
因此,现在当我想要一个 printf 语句时,例如,如果我输入 printf,我不会得到 Intellisense 提示。但是,如果我 Ctrl+Space 或 Ctrl+J Intellisense 正在识别该命令,并且它会显示出来。下面是 Intellisense 未自动工作的图像。
现在,如果我输入 std::printf,则会出现 Intellisense:
有什么方法可以让 VS2010/Intellisense 知道我想使用 std 命名空间,因为它似乎只是无法识别“#using 命名空间标准;”命令。
非常感谢。
All,
I have a strange issue with Intellisense for C++ projects. Background: I have recently installed VS2010 Sp1 and had a loss of Intellisense with SQL Server 2008 R2. I tried installing Cumulative Update 7 (CU7) as recommended and this did not work. Reinstalling SQL Server 2008 R2 however, did. I then updated using CU7 for SQL Server 2008 R2 and all was good. Now Intellisense works fine for C# projects but now for C++ projects it is not quite working as it should (NOTE: C++ project is not C++/CLI).
I have disabled Precompiled Header ("Not Using Precompiled Headers") and have the following includes:
#include <cmath>
#include <complex>
#include <iostream>
#include "stdafx.h"
#include "globals.h"
using namespace std;
NOTE: I am aware that using the std namespace is not always considered best practise, but here it will save me allot of time and there is no chance of ambiguity.
So now when I want a printf statement for example, if I type printf I get not Intellisense prompt. However, if I Ctrl+Space or Ctrl+J Intellisense is recognising the command, and it shows up. Below is the image of Intellisense not automatically working.
Now if I type std::printf, Intellisense appears:
Is there any way to let VS2010/Intellisense know I want to use the std namespace because it appears like it is just not recognising the "#using namespace std;" command.
Thanks very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
注意:我的第二个答案。基于 Cory Nelson 的评论,所以我不声称功劳。
如果我理解正确的话,您希望智能感知在您输入“p”时弹出。
答案是:不,VS2010 不会这样做。
智能感知将对“::p”或“std::p”起作用,但不适用于普通的“p”。这与预编译头无关,也与
#include
顺序无关。它只是不会。我过去使用过的一些 IDE 有一个在这种情况下启用/禁用完成的设置(我记得在某些 C++ Builder 版本中看到过),但我在 VS2010 中找不到它。
那么为什么VS2010不允许呢?关键字可能会导致不值得解决的问题,但这是否就是原因呢?我不知道。也许 VS 团队的成员可以解释一下这一点。
更新:
我在一个新的 VS2010 项目中测试了这个程序:
输入“stri”时没有弹出窗口。
“string”出现在 ctrl-space 之后的弹出窗口中,当我删除
using namespace std;
时,它不存在,因此它可以正确地对using
做出反应。输入
::
后,智能感知将激活,并且在::s
后建议 SA_AccessType(来自文件 sourceannotations.h),因此该列表显然已预先填充了许多系统标头。如果我输入
if
并强制弹出 Intellisense,则列表中没有if
。如果我然后输入(
就像我想输入if(
一样,它会更正为ifstream(
。所以 if Intellisense 总是会弹出,输入关键字会困难得多。Note: My second answer. Based on a comment by Cory Nelson, so I don't claim credit.
If I understand you correctly, you want that Intellisense pops up the moment you type 'p'.
The answer is: No, VS2010 won't do that.
Intellisense will kick in for "::p" or "std::p", but not for a plain "p". This has nothing to do with precompiled headers, nor
#include
order. It just won't.Some of the IDEs I've worked with in the past have a setting to enable/disable completion in this case (I recall seeing so in some C++ Builder version), but I couldn't find it in VS2010.
So why would VS2010 not allow it? Keywords could cause problems that are not worth solving, but whether that's the reason here? I don't know. Maybe a member of the VS team could shed some light on this.
Update:
I tested this program in a new VS2010 project:
No popup while typing "stri".
"string" appears in the pop-up after ctrl-space, and is absent when I remove the
using namespace std;
so it correctly reacts to theusing
.After typing
::
, Intellisense activates and after::s
suggests SA_AccessType (from the file sourceannotations.h), so the list is clearly prepopulated with many system headers.If I type
if
and force Intellisense to pop-up, there is noif
in the list. If I then type the(
as if I wanted to typeif(
, it corrects toifstream(
. So if Intellisense would always pop-up, it would be much harder to type keywords.从您的
#include
列表来看,printf()
尚未声明。毕竟,它是在
/
中声明的。所以 Intellisense 不显示它是正确的。 ;)
在顶部添加
#include
的优点是不需要using namespace std;
,因为;
将名称放入全局命名空间(也可能放入 std:: 命名空间)。更新:这并不能解释为什么在输入“std::pri”后出现“std::printf”。
UPDATE2:经过测试,很明显,当按ctrl-space强制时,会提示
printf
。也许问题是为什么 Intellisense 不会自动弹出?Judging on your list of
#include
,printf()
hasn't been declared. After all, it's declared in<stdio.h>
/<cstdio>
.So Intellisense is right not to show it. ;)
Adding an
#include <stdio.h>
to the top has the advantage that nousing namespace std;
is required, as<stdio.h>
puts the names in the global namespace (and possibly in the std:: namespace as well).UPDATE: This does not explain why "std::printf" shows up after typing "std::pri".
UPDATE2: After testing, it is clear that
printf
will be suggested when forced by ctrl-space. Maybe the question is why Intellisense does not automatically pop up?这种类型的 C++ 智能感知仅在您按下 ctrl+space 后才会出现。
商业扩展 Visual Assist X 提供的体验可能更符合您的需求(请注意,它不是Visual Studio Express 版本支持)。
That type of C++ intellisense only appears after you hit ctrl+space.
The commercial extension Visual Assist X gives an experience that may be more what you are looking for (note that it is not supported in express editions of Visual Studio).