C++ 流对象可以';t使用<&书信电报;操作员C++;

C++ 流对象可以';t使用<&书信电报;操作员C++;,c++,file-io,C++,File Io,我试图向文件中写入一些文本,但在为ofstream类定义了对象之后,我得到了一个错误,即“;”在我使用的地方,您的tofile是在if块(单个语句块)中声明的,因此它只具有该块的范围。将声明移动到声明其余变量的位置。您的tofile在if块(单个语句块)中声明,因此它仅具有该块的范围。将声明移动到声明其余变量的位置。您的tofile在if块(单个语句块)中声明,因此它仅具有该块的范围。将声明移动到声明其余变量的位置。您的tofile在if块(单个语句块)中声明,因此它仅具有该块的范围。将声明移动

我试图向文件中写入一些文本,但在为ofstream类定义了对象之后,我得到了一个错误,即“;”在我使用的地方,您的
tofile
是在
if
块(单个语句块)中声明的,因此它只具有该块的范围。将声明移动到声明其余变量的位置。

您的
tofile
if
块(单个语句块)中声明,因此它仅具有该块的范围。将声明移动到声明其余变量的位置。

您的
tofile
if
块(单个语句块)中声明,因此它仅具有该块的范围。将声明移动到声明其余变量的位置。

您的
tofile
if
块(单个语句块)中声明,因此它仅具有该块的范围。将声明移动到声明其余变量的位置。

tofile在if语句中的一个非常小的范围内定义。您需要扩大范围以允许写入文件。tofile是在if语句的一个非常小的范围内定义的。您需要扩大范围以允许写入文件。tofile是在if语句的一个非常小的范围内定义的。您需要扩大范围以允许写入文件。tofile是在if语句的一个非常小的范围内定义的。您需要扩大范围以允许写入文件
#include <iostream>
#include <SFML/Network.hpp>
#include<fstream>


using namespace std;


bool port_open(const string& address, int port)
{
    sf::TcpSocket socket;
    bool open = (socket.connect (sf::IpAddress(address), port)==sf::Socket::Done);
    socket.disconnect();
    return open;
}
int main()
{ string address;
  int port, check, in_port, fin_port;
  char write_check;
  cout<<"Press 1 for single port and 2 to check the range of ports.";
  cin>>check;


  switch(check)
  {case 1:
      {
  cout<<"Enter the ip address of the client: ";
  std::cin>>address;

  cout<<"Enter the port to scan: ";
  cin>>port;

  if(port_open(address, port))
      cout<<"The port "<<port<<" at IP:"<<address<<" is OPEN."<<endl;
  else 
      cout<<"The port "<<port<<" at IP:"<<address<<" is CLOSED.";
  break;
      }

  case 2:
      {
       cout<<"Enter the ip address of the client: ";
       cin>>address;

  cout<<"Enter the port from where scanning has to be started ";
  cin>>in_port;
  cout<<"Enter the port upto which scanning has to be done. ";
  cin>>fin_port;

  cout<<"Would you like to have the log in text file? y/n";
  cin>>write_check;

  if (write_check=='y')
     std::ofstream tofile ("Log.txt");



  for(int j=in_port; j<=fin_port; j++)
  {
      cout<<"Scanning port "<<j<<" on IP "<<address<<"...\n";
    if (write_check=='y')
      tofile <<"Scanning port "<<j<<" on IP "<<address<<"...\n";  //ERROR a ';' is expected (after tofile)

   if(port_open(address, j))
      {
          cout<<" OPEN."<<endl;
       if (write_check=='y')
            tofile<<"OPEN."<<endl;     //ERROR a ';' is expected (after tofile)
   }
  else 
     {
         cout<<" CLOSED."<<endl;
      if (write_check=='y')
          tofile<<"CLOSED."<<endl;       //ERROR a ';' is expected (after tofile)
     }
   }
  break;}
  }

  system("pause");
  return 0;
}