Can we have vector of vector?
e.g.
vector <vector<string>>vBig;
Printable View
Can we have vector of vector?
e.g.
vector <vector<string>>vBig;
Yes.
Thanks a lot nvoigt. :-)
But you need to put a space between the two >, or the compiler will parse it as a >> operator.
Thanks a lot CornedBee
AFAIK, MSVC has been smart enough to spot inccorect usage of templates in form of >> since earlier versions. It would complain >> is invalid with templates, it must be > >, but it doesn't report syntax error. It's just Microsoft went one step further to eleminate the restriction in later versions.
I don't really understand why the standard specifies you must use > > either, since it's rather absurd. It doesn't really matter if it can be mistaken for the operator or not, since it's the compiler vendor's work to make sure it works. It messes up style too. Microsoft's compiler can do it, so why not others?
Looking on the good side, at least the non-portable code will become standard (and hopefully portable) in a few years' time (C++0x).Quote:
According to the standard probably, but newer versions of MSVC have actually been made smart enough to work out what you mean when you use >> there, if it can.
Note that this is not really a good thing either as it encourages you to write non-portable code.
The principle of greedy matching. However, eventually the C++ standard committee people decided that it is better to just let the more natural syntax be used, thus the change.Quote:
I don't really understand why the standard specifies you must use > > either, since it's rather absurd.
Yeah, and another thing I hate about MSVC is that it doesn't complain if you forget to include a standard header file and silently includes it for you. Then you try compiling on UNIX and get errors about the missing header files. Maybe there's a switch to turn off that "feature", but I haven't been motivated enough to look for it yet.
There's an option to turn off Microsoft extensions. Only problem is that it's rather useless since it produces tons of errors if you include typical Windows headers!
I'm thinking you should be able to turn off (and on) an option dynamically; otherwise it's rather useless.
It does no such thing. It's just that some standard library parts are implemented in terms of other parts. For example, some parts of <locale> require the std::string class. Also, some parts of the stream library require locales. Thus, when you #include <iostream>, you get parts of the locale system and thus parts of the string library.
This problem affects all standard libraries, but to different degrees. Some go to greater pains in order to avoid this stuff, others to lesser. In one library you may get A by including B, in the other you may get B by including A. And so on.
Nothing MS-specific.
Oh I would have to disagree with the "Nothing MS-specific" part. If you forget even a single header file gcc will complain, but MSVC compiles without so much as a peep. Whether this is intentional or simply because required headers were included by other headers, I don't know, but the result is annoying nonetheless.
I have not encountered this to my knowledge. What functions is that and what headers?
Here's an example where <cstdio> & <cstring> are required, but VC++ compiles it anyways. They're probably included in <iostream> because if you remove that, you get the expected errors.
Code:#include <iostream>
//#include <cstdio>
//#include <cstring>
using namespace std;
int main()
{
char str[] = "fdsfsdfsdfs";
printf( "str has %d chars", strlen( str ) );
return 0;
}
Indeed. They are included automatically. I find it convenient, though, not annoying.Code:1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\iostream
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\istream
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\ostream
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\ios
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\xlocnum
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\climits
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\yvals.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\sal.h
1>Note: including file: h:\apps\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtassem.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\vadefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\use_ansi.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\limits.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\cstdio
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\stdio.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\swprintf.inl
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\cstdlib
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\stdlib.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\streambuf
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\xiosbase
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\xlocale
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\cstring
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\string.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\stdexcept
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\exception
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\xstddef
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\cstddef
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\stddef.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\eh.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\malloc.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\xstring
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\xmemory
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\new
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\xutility
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\utility
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\iosfwd
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\cwchar
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\wchar.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\wtime.inl
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdbg.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\typeinfo
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\xdebug
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\xlocinfo
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\xlocinfo.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\ctype.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\locale.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: H:\Apps\Microsoft Visual Studio 9.0\VC\include\share.h
I don't see what's so wrong with it?
Remarkably, the MinGW port of g++ 3.4.5 compiles your example without errors even with -Wall. The Comeau online compiler finds it okay too.
Then stuff all common includes in one header and include it in your projects. Problem fixed.
Well, it goes to show that the problem is not MS specific.Quote:
Actually, I only tried this particular example on VC++, but I remember seeing a problem like this where I was missing some C headers...
Allowing '>>' in template declarations seems like a simple enough requirement, but the amount of work required in the compiler's parser would be ridiculous in comparison to the benefit of allowing it, which is practically zero.
And the idea of a standards body is to formalize and enhance existing practice, not to subject implementers to onerous, pointless requirements. It's not, "We create the standard and now you have to do it this way," it's practically the exact opposite.
Of course, now that compiler vendors have had time to make the necessary changes to handle >>, they will be changing the next standard to allow it.
In this case, not allowing >> is odd and forcing compiler vendors to support it makes sense once they have enough time to do so.
MSVS 6, 2003, and 2005 all have had this 'auto-include' of headers for quite some time. The problem comes when it demands you must include some headers but yet does not enforce you including others that the code clearly needs. It has something to do with your project options and which 'common' libraries/headers, if any, you wish to use. By default MSVS knows where the standard libraries are as well as the headers. Once you install Platform SDK and integrate it into VS it usually also knows where to find the Platform SDK files. There are times when you can get away with not including Platform SDK headers and it will still compile.
However what is very odd in VS is Intellisense. Often it shows functions, variables, etc, that look to be accessible and yet often when you compile it complains of unresolved externals or undefined symbols. Intellisense often does not match exactly what is 'visible' at the current location in your code. Often times it shows functions and methods that are clearly not accessible yet it appears they are. This is extremely annoying. Other times Intellisense just completely fails to show anything, does not update correctly when you alter headers, or gets corrupted.
That behavior was changed in MSVC8 (aka 2005). It actually needs the proper headers to be able to see the functions.
Yes, IntelliSense support is quite old by now, though I've heard they'll be updating it for the next version. Thank the gods for that; it's quite a mess right now.Quote:
Other times Intellisense just completely fails to show anything, does not update correctly when you alter headers, or gets corrupted.