I want to make an if statment that checks for the size of a text file. What is the syntax to declare that?

if( txtfile.txt = 5kb || txtfile.txt = 10kb )
{
blah blah
}
?????

thanks

A portable way to retrieve the file size :icon_razz:

// Returns number of bytes in a file
int GetFileSize(char *file) {
  // Open file
  std::ifstream f(file, std::ios_base::binary | std::ios_base::in);

  // Make sure it's opened correctly
  if ( !f.good() || f.eof() || !f.is_open() ) {
    return 0;
  }

  // Beginning of file
  f.seekg(0, std::ios_base::beg);
  std::ifstream::pos_type begin_pos = f.tellg();

  // End of file
  f.seekg(0, std::ios_base::end);

  // Return the difference
  return static_cast<int>(f.tellg() - begin_pos);
}
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.