Intellisense for C++ in VS2010
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 s开发者_如何学Gohows 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.
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:
#include <string>
using namespace std;
int main()
{
stri
}
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 the using
.
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 no if
in the list. If I then type the (
as if I wanted to type if(
, it corrects to ifstream(
. So if Intellisense would always pop-up, it would be much harder to type keywords.
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 no using 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?
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).
精彩评论