UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C++
  • » ISO C++ forbids declaration of 'i' with no type

#1 2008-10-28 12:59 AM

waytovietnam
Guest

Re: ISO C++ forbids declaration of 'i' with no type

#include <iostream>
using namespace std;

int main()
{
for (register i = 1; i <= 9; ++i)
for (register j = 1; j <= 9; ++j)
cout << i << " x " << j << " = " << i*j << '\n';

return 0;
}

I keep getting two errors saying ISO c++ forbids declaration of 'i' with no type and another one that says ISO c++ forbids declaration of 'j' with no type. I can't figure out what's wrong. I am new to this by the way and doing sample programs and i haved it typed out exactly how they do. Any help would be appreciatied!
Thanks in advance

#2 2008-10-28 01:51 AM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: ISO C++ forbids declaration of 'i' with no type

"register" isn't a type, it's just a modifier... the type you presumably want for your counters is 'int'.  So what you really want is this:

[...]
for (register int i = 1; i <= 9; ++i)
   for (register int j = 1; j <= 9; ++j)
      cout << i << " x " << j << " = " << i*j << '\n';
[...]
return 0;

Note that the "register" keyword isn't really necessary or useful anyway, these days... so you'd be just as well off omitting it.  Modern compilers are smart enough to know when it's appropriate to place a variable into a register without hints from the programmer, and for that reason most of them will simply ignore the register keyword.

Offline

#3 2008-10-28 05:35 PM

waytovietnam
Guest

Re: ISO C++ forbids declaration of 'i' with no type

Thanks for your kid comment but why did you remove my signature??

#4 2008-10-28 05:58 PM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: ISO C++ forbids declaration of 'i' with no type

Offline

#5 2008-10-30 06:44 PM

waytovietnam
Guest

Re: ISO C++ forbids declaration of 'i' with no type

  • Index
  • » C++
  • » ISO C++ forbids declaration of 'i' with no type

Board footer

Powered by FluxBB