C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 01-02-2008, 04:22 AM   #1
Registered User
 
Join Date: Jan 2008
Posts: 24
Question Can we have vector of vector?

Can we have vector of vector?
e.g.
vector <vector<string>>vBig;
ketu1 is offline   Reply With Quote
Old 01-02-2008, 04:48 AM   #2
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,754
Yes.
__________________
hth
-nv

She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

When in doubt, read the FAQ.
Then ask a smart question.
nvoigt is offline   Reply With Quote
Old 01-02-2008, 05:27 AM   #3
Registered User
 
Join Date: Jan 2008
Posts: 24
Thanks a lot nvoigt. :-)
ketu1 is offline   Reply With Quote
Old 01-02-2008, 05:53 AM   #4
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,439
But you need to put a space between the two >, or the compiler will parse it as a >> operator.
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 01-02-2008, 05:55 AM   #5
Registered User
 
Join Date: Jan 2008
Posts: 24
Thanks a lot CornedBee
ketu1 is offline   Reply With Quote
Old 01-02-2008, 12:32 PM   #6
Algorithm Dissector
 
iMalc's Avatar
 
Join Date: Dec 2005
Location: New Zealand
Posts: 2,476
Quote:
Originally Posted by CornedBee View Post
But you need to put a space between the two >, or the compiler will parse it as a >> operator.
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.
__________________
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
iMalc is offline   Reply With Quote
Old 01-02-2008, 12:35 PM   #7
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
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?
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 01-02-2008, 12:35 PM   #8
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,368
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.
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:
I don't really understand why the standard specifies you must use > > either, since it's rather absurd.
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.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 01-02-2008, 12:42 PM   #9
and the hat of sweating
 
Join Date: Aug 2007
Location: Toronto, ON
Posts: 3,122
Quote:
Originally Posted by iMalc View Post
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.
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.
cpjust is offline   Reply With Quote
Old 01-02-2008, 12:46 PM   #10
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
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.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 01-02-2008, 01:05 PM   #11
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,439
Quote:
Originally Posted by cpjust View Post
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.
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.
__________________
All the buzzt!
CornedBee

"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
CornedBee is offline   Reply With Quote
Old 01-02-2008, 02:44 PM   #12
and the hat of sweating
 
Join Date: Aug 2007
Location: Toronto, ON
Posts: 3,122
Quote:
Originally Posted by CornedBee View Post
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.
cpjust is offline   Reply With Quote
Old 01-02-2008, 02:48 PM   #13
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
I have not encountered this to my knowledge. What functions is that and what headers?
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 01-02-2008, 02:52 PM   #14
and the hat of sweating
 
Join Date: Aug 2007
Location: Toronto, ON
Posts: 3,122
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;
}
cpjust is offline   Reply With Quote
Old 01-02-2008, 03:00 PM   #15
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
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
Indeed. They are included automatically. I find it convenient, though, not annoying.
I don't see what's so wrong with it?
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
can some one please tell me the cause of the error ? broli86 C Programming 8 06-26-2008 08:36 PM
syntax help? scoobygoo C++ Programming 1 08-07-2007 10:38 AM
Vector class Desolation C++ Programming 2 05-12-2007 05:44 PM
Need some help/advise for Public/Private classes nirali35 C++ Programming 8 09-23-2006 12:34 PM
Certain functions Lurker C++ Programming 3 12-26-2003 01:26 AM


All times are GMT -6. The time now is 01:25 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22