How many chars(i.e. A) does it take to fill up 1 megabyte?
How many chars(i.e. A) does it take to fill up 1 megabyte?
It depends on your system, but on most platforms a char is 1 byte.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Well one megabyte is 1,048,576 bytes and the 'char' type in C++ is at least 8 bits (or one byte) but I don't think the standard guarantees it is always one byte in size.
Also, it depends on the character encoding. ASCII, for example, uses 7 bits for each character while for Unicode the size of each character can vary. (See this tutorial for more info)
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
I found another way to do what I am trying to do. I can just compare the size of the file to the original size of the file... just need to know how now.
The comments are what I need to do.
Code:See new post.
Last edited by bikr692002; 04-05-2006 at 03:05 PM.
Just a tip for you, a new programmer......these are not operations you want to be messing around with until you're very familiar to programming.Code:std::cout<<"To select Secure Disk Wipe, input SDW.\n"; std::cout<<"To select Secure Disk Cleanse, input SDC.\n";
Sent from my iPadŽ
I am making my own way, if you take a look at the selections, I am using my own method of Cleansing the disk and I am going to figure out a way to (safely) wipe it.Originally Posted by SlyMaelstrom
Code:#include <fstream> #include <iostream> #include <windows.h> int main() { std::string File,Option; int Loop,SizeOfDisk,SizeOfFile,OrigSizeOfFile; Loop=1; std::cout<<"Welcome to C.J.'s Security 'suite'!\n"; std::cout<<"Please enter what you want to do.\n"; std::cout<<"To select Secure Disk Wipe, input SDW.\n"; std::cout<<"To select Secure Disk Cleanse, input SDC.\n"; std::cout<<"To select Secure File Deletion, input SFD.\n"; std::cout<<"To select ---this option is not yet available---.\n"; std::cout<<"To select ---this option is not yet available---.\n"; std::cout<<"Option:"; getline(std::cin,Option,'\n'); if(Option=="SDW") { std::cout<<"Sorry,This option is not yet available"; std::cin.get(); } if(Option=="SDC") { std::cout<<"Please enter Disk letter(Only letter):"; getline(std::cin,File,'\n'); if(File.length()!=2) { while(Loop==1) { File=""; std::cout<<"\nPlease enter Disk Letter Only:"; getline(std::cin,File,'\n'); if(File.length()==2) { Loop=0; } } Loop=1; } File=File+":\\SecureDiskCleanse.txt"; std::ofstream a_file(File.c_str()); while(Loop==1) { a_file<<"Secure Disk Cleanse."; /*CheckSizeOfDisk*/ if(SizeOfDisk==0) { Loop=0; } } a_file.close(); File="DEL "+File; system(File.c_str()); std::cin.get(); } if(Option=="SFD") { std::cout<<"Please enter file path and name.:"; getline(std::cin,File,'\n'); /*GET ORIGINAL SIZE OF FILE*/ std::ofstream a_file(File.c_str(), std::ios::trunc); while(Loop==1) { a_file<<"Secure File Deletion."; /*GET SIZE OF FILE*/ if(SizeOfFile>(OrigSizeOfFile+10)) { Loop=0; } } a_file.close(); File="DEL "+File; system(File.c_str()); std::cin.get(); } else { std::cin.get(); } return 0; }
Yeah, you're making a system() call to "DEL"... that's not exactly secure. You see, messing with file deletion is like juggling knives... you better know exactly what you're doing before you attempt it.
Sent from my iPadŽ
hope you've got good backups!
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
I know ^_^ Thanks for your warning though. I am putting in error checking to make shure that the input is legit...
>>but I don't think the standard guarantees it is always one byte in size
Yes, the standards say one character = 1 byte. But does not say how may bits make up that byte. I've heard there are some 4-bit operating systems, where 1 byte = 4 bits. But there are also 128-bit operating systems where 1 byte = 128 bits. And in the next year or so MS-Windows will be a 64-bit operating system where 1 byte = 64 bits.
Just use this program
Code:#include <iostream> using namespace std; int main() { cout << "The size of an int is:\t\t" << sizeof(int) << " bytes.\n"; cout << "The size of a short int is:\t" << sizeof(short) << " bytes.\n"; cout << "The size of a long int is:\t" << sizeof(long) << " bytes.\n"; cout << "The size of a char is:\t\t" << sizeof(char) << " bytes.\n"; cout << "The size of a float is:\t\t" << sizeof(float) << " bytes.\n"; cout << "The size of a double is:\t" << sizeof(double) << " bytes.\n"; cin.get(); }
Careful! that's not quite right.Originally Posted by Ancient Dragon
I don't have the standard here, so I can't check what it say's about one char = one byte, but you're probably right about that.
But to say that on a 64-bit os a byte is 64 bits is totally wrong. You use win32 at the moment. Tell me, is a byte on XP 32 bits? You're confusing pointer size with byte size (that's actually an over-simplification, but it'll do for now).
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
Well, how can I check the free space on a harddrive and the size of particular files???
that's fairly platform dependant. if you're happy to write platform-dependant code, there should be plenty on msdn.Originally Posted by bikr692002
Otherwise you could look at boost.filesystem which I think has some functions that'll help you.
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?