Hello,
the following code doesn't work.
The compiler gives the message: crosses initialization of 'std::ofstream filestream
Maybe someone could explain the reason for this.

switch(x)
      {  
        case '7':
        ofstream filestream("Test.txt",ios::out|ios::app);
        //...
        break;

        case '8':
        cout<<This is a test.";
        break;
      } 

use brackets or declare ofstream object before the switch statement.

switch(x)
      {  
        case '7':
        {
            ofstream filestream("Test.txt",ios::out|ios::app);
            //...
        }
        break;

        case '8':
        cout<<This is a test.";
        break;
      } 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.