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
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
http://msdn.microsoft.com/en-us/library/aa364946(VS.85).aspx
:) or you could probably count the number of characters in the file in binary mode the multiple it by 8??
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);
}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.