hi all ,as I know the C++ line spaces and the tab characters and the comments are
dropped out when it passing the C++ lexer state on typical C++ compiler.
But in the visual studio C++ 6.0 The things not work always like this to me . I don't know where is the bug. But what I find is when I drop a line space it given errors.
Compile error source code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <vector>
#include <iostream>
using namespace std ;
using std::vector;
int main ()
{
// Declare size of two dimensional array and initialize
vector<vector<int>> vI2Matrix(3,vector<int>(2,0));
vI2Matrix[0][0] = 0 ;
vI2Matrix[0][1] = 1 ;
vI2Matrix[1][0] = 10 ;
vI2Matrix[1][1]= 11 ;
vI2Matrix[2][0] = 20 ;
vI2Matrix[2][1] = 21;
cout << "Loop by index :" << endl ;
int ii , jj ;
for ( ii = 0 ; ii < 3 ; ii++)
{
for ( jj=0 ; jj < 2 ; jj++)
{
cout << vI2Matrix[ii][jj] << endl ;
}
}
return 0;
}
|
The corrected source code. see the line space on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <vector>
#include <iostream>
using namespace std ;
using std::vector;
int main ()
{
// Declare size of two dimensional array and initialize
vector<vector<int> > vI2Matrix(3,vector<int>(2,0));
vI2Matrix[0][0] = 0 ;
vI2Matrix[0][1] = 1 ;
vI2Matrix[1][0] = 10 ;
vI2Matrix[1][1]= 11 ;
vI2Matrix[2][0] = 20 ;
vI2Matrix[2][1] = 21;
cout << "Loop by index :" << endl ;
int ii , jj ;
for ( ii = 0 ; ii < 3 ; ii++)
{
for ( jj=0 ; jj < 2 ; jj++)
{
cout << vI2Matrix[ii][jj] << endl ;
}
}
return 0;
}
|
see the difference ,
vector<vector<int>> vI2Matrix(3,vector<int>(2,0));
vector<vector<int> > vI2Matrix(3,vector<int>(2,0));
on the line two there is a additional space between the > and > . see it.
the line one gives a compile time error, but the line 2 compiles successfully.
But the problem is , can anybody show me the difference between the line 2 and line 1.
I'm confused . May be this will be working proper on the Dev C++ , ( gnu C++ gcc). Please use the visual C++ 6.0 to regenerate this bug ,may be the latest versions are fixed this bug.