c++ - New ISO scoping rule for " for LOOP" -


i have piece of code written else before new iso come effect.

the for loop in for (pa=a.begin(), i=0; pa != a.end(); ++pa) has little trouble executing because of i=0 part of syntax. also, had prefix other for loop syntaxes read for ( int .....) int before i. however, don't know how fix int i=0 in line: for (pa=a.begin ( ), i=0; pa != a.end ( ); ++pa). please me out.

  ( int = 0; pa != a.end(); ++pa)       *pa = ++i;    (int i=0; i<10; i++)       std::cout << "a[" << << "]=" << a[i] << std::endl;    // int i;  // note work, not want line.    (pa=a.begin(), i=0; pa != a.end(); ++pa)       std::cout << "a[" << i++ << "]=" << *pa << std::endl; 

an declaration outside for loop sensible way have 2 iteration variables of unrelated types in c++98 , later versions of language. initialiser can either single expression or single declaration, , declaration can't declare variables of multiple unrelated types.

if want one-liner in situation, use monstrosity:

for (int = ((pa = a.begin()), 0); pa != a.end(); ++pa, ++i) 

if sort of thing regularly, make sure no-one maintains code knows live.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -