-
extra braces inside main
I ran across this code and was wondering what the extra braces are there for?
Code:
int main()
{
const int sz = 100; // Buffer size;
char buf[sz];
{
ifstream in("Strfile.cpp"); // Read
assure(in, "Strfile.cpp"); // Verify open
ofstream out("Strfile.out"); // Write
assure(out, "Strfile.out");
int i = 1; // Line counter
// A less-convenient approach for line input:
while(in.get(buf, sz))
{
in.get(); // Throw away next character (\n)
cout << buf << endl; // Must add \n
out << i++ << ": " << buf << endl;
}
} // Destructors close in & out
} ///:~
It seems very odd to me but compiled fine when i removed the assure function calls. I also removed the ofstream stuff, but i think it would compile with that in there also
-
They have no purpose in the posted code, other than to potentially prevent all variables declared in there from being used in the code after the last red }.
They just define another scope block. As a result, all variables declared inside that block, exist only until that block ends, then they're gone.
Quzah.