#include <fstream> std::ifstream::pos_type filesize(const char* filename) { std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary); return in.tellg(); }
See http://www.cplusplus.com/doc/tutorial/files/ for more information on files in C++.
edit: this answer is not correct since tellg() does not necessarily return the right value. See http://stackoverflow.com/a/22986486/1835769
Related Posts:
- What is a segmentation fault?
- Sleep for milliseconds
- C++ Cout & Cin & System “Ambiguous” [closed]
- Regular cast vs. static_cast vs. dynamic_cast
- What is an unsigned char?
- C++ std::priority_queue uses the lambda expression
- When to use reinterpret_cast?
- Expression must be a modifiable lvalue
- How to read a file line by line or a whole text file at once?
- Split a string using C++11
- error: expected unqualified-id error: Meaning and fix? [duplicate]
- How to track down a “double free or corruption” error
- undefined reference to `WinMain@16′
- How can I clear console
- How to go from fopen to fopen_s
- TranslateName() function doesn’t work on win10
- How to use the PI constant in C++
- How to concatenate two strings in C++?
- How to get current time and date in C++?
- where is the official c++ documentation
- wntdll.pdb not loaded – Can’t see the exception
- Networking with C++
- Error a function-definition is not allowed here before ‘{‘ token
- invalid new-expression of abstract class type error
- How can I create objects while adding them into a vector?
- what does “error : a nonstatic member reference must be relative to a specific object” mean?
- “Symbol(s) not found for architecture x86_64” on QtCreator project
- MinGW: “gcc is not recognized as an internal or external command”
- Convert Python program to C/C++ code?
- How to debug ‘Stack smashing detected’?
- basic_string::_M_construct null not valid after constructing subvector of strings
- Does C++ have a Garbage Collector?
- Is “argv[0] = name-of-executable” an accepted standard or just a common convention?
- How to fix ‘std::logic_error’ what(): basic_string::_M_construct null not valid error?
- What does the assignment of ~0u to a variable mean in C++?
- expected expression in C++?
- How to access the contents of a vector from a pointer to the vector in C++?
- printf with std::string?
- warning: control reaches end of non-void function [-Wreturn-type]
- Program received signal SIGSEGV, Segmentation fault
- gcc/g++: “No such file or directory”
- Error: expected type-specifier before ‘ClassName’
- General way of solving Error: Stack around the variable ‘x’ was corrupted
- error MSB3073: How do I fix this?
- timestamp of time(0) at multiple places in a C++ program
- What’s the most efficient way to erase duplicates and sort a vector?
- How can I iterate through a string and also know the index (current position)?
- c++ parse int from string [duplicate]
- C++ array assign error: invalid array assignment
- Is there a median function in the C++ library?
- Determine if map contains a value for a key?
- What does “Permission denied” “Id returned 1 exit status” mean?
- When does an Incomplete Type error occur in C++
- std::cin input with spaces?
- extended initializer lists only available with
- how to initialize an empty integer array in c++
- What does |= mean in c++
- Error: cannot declare variable ‘c’ to be of abstract type ‘circle’
- Static linking vs dynamic linking
- What is object slicing?
- Java equivalent of cin (C++)
- g++ “because the following virtual functions are pure” with abstract base class
- why can’t I dereference an iterator?
- expected identifier before string constant
- C++ error: expected identifier before “(” token
- Function for C++ struct
- C++ error: double free or corruption (fasttop)
- no match for ‘operator<<’ in ‘std::operator
- Case insensitive string comparison C++
- C++ Exception thrown: read access violation. this was nullptr
- C++ getInt() function (have a java equivalent attached)
- Simple string parsing with C++
- member access within null pointer of type ‘struct ListNode’
- How does c++ represent negative value
- error: switch quantity not an integer
- How to create a vector of class objects in C++?
- Is clrscr(); a function in C++?
- Cross compiler prefix and path in eclipse
- How to write log base(2) in c/c++
- Reading a string from file c++
- Incrementing in C++ – When to use x++ or ++x?
- Use of undefined type [duplicate]
- Warning : overflow in implicit constant conversion
- C++ multiline string literal
- Getting a bunch of crosses initialization error
- c++ a heap has been corrupted error when running the program
- Expected unqualified-id before ‘[‘ token
- C++ Error: Invalid conversion from ‘char’ to ‘const char*’
- cc1.exe System Error – libwinpthread-1.dll missing – But it isn’t
- Make / gcc cryptic error 2: how to have more information?
- REGSVR32: the module “xxxxx.dll” failed to load … dependent assembly could not be found
- Error: expression cannot be used as a function?
- What is a .h.gch file?
- MinGW .exe requires a few gcc dll’s regardless of the code?
- Converting bool to text in C++
- clearing a vector of pointers [duplicate]
- Evaluate a string with a switch in C++ [duplicate]
- C++ JSON Serialization
- stack around the variable…was corrupted
- Creating a list to hold objects in C++