I don't see any errors in my code but I guess there is alot... I think most have to do with using strings...
Code:Updated code on other post.
I don't see any errors in my code but I guess there is alot... I think most have to do with using strings...
Code:Updated code on other post.
Last edited by bikr692002; 04-05-2006 at 12:42 PM.
Step one if you are using the string class, #include <string>. After that, post the error messages and indicate the lines they refer to.
Ok, I'll do that after my essay is done...Originally Posted by Daved
You might want to try the using namespace std; statement so you don't have to keep typing std::*
>> std::ofstream a_file(FilePath, std::ios::trunc);
File streams take const char* arguments. Use FilePath.c_str() instead of FilePath. Do the same for any other file stream constructors.
>> You might want to try the using namespace std; statement so you don't have to keep typing std::*
I think it's better the way it is.
Thanks for all your help so far, now it's just giving me errors when I try to combine strings... like
File=FileName+A+FileType
Oh and I use std:: because I feel I have more control over the program and it is more efficient.Code:#include <string> #include <fstream> #include <iostream> #include <windows.h> int main() { int A,B,C; std::string Del,File,Path,Delete,Option,FilePath,FileName,FileType; Del="Del "; FileName="SDC"; FileType=".txt"; 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=="SDC") { std::cout<<"Please enter amount of files you want created (to overwrite deleted data)"; std::cin>>C; for(A=0;A<C;A++) { File=FileName+A+FileType; std::ofstream a_file(File.c_str()); for(B=0;B<3000;B++) { a_file<<"Secure Disk Cleanse. "; } a_file<<"This program was made by\nCharles Staal.\n"; a_file<<"130 Gregory Way\nCalverton,New York\n11933"; a_file.close(File); } for(A=0;A<C;A++) { File=FileName+A+FileType; Delete=Del+File; system(Delete.c_str()); } std::cout<<"\n\nFinished"; std::cin.get(); } if(Option=="SFD") { std::cout<<"Please enter file path.\n"; getline(std::cin,Path,'\n'); std::cout<<"Please enter File name.\n"; getline(std::cin,File,'\n'); FilePath=Path+File; std::ofstream a_file(FilePath.c_str(), std::ios::trunc); for(A=0;A<3000;A++) { a_file<<"Secure File Deletion "; } a_file<<"This program was made by\nCharles Staal.\n"; a_file<<"130 Gregory Way\nCalverton,New York\n11933"; a_file.close(File); Delete=Del+File; system(Delete.c_str()); std::cin.get(); } std::cin.get(); return 0; }
You didn't post the error messages.
>> getline(std::cin,Option,'\n');
That should probably be std::getline.
>> File=FileName+A+FileType
A is an int. You cannot just add an int to a string. If you want to combine that information into a single filename, use a stringstream from <sstream>. Check your book or online reference for details on how to use it.
Is there no alternative to that? Because I think that will mess up my loops.
It won't mess up your loops. There are alternatives, but they would behave the same way.
Well, I ended up using iota()
^_^ HappyhappyjoyjoyCode:#include <fstream> #include <iostream> #include <stdlib.h> #include <windows.h> int main() { char FileNum[8]; int FileLines,FileNumber,DesiredAmountOfFiles; std::string Del,File,Path,Delete,Option,FilePath,FileName,FileType; Del="Del "; FileName="SDC"; FileType=".txt"; 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=="SDC") { std::cout<<"Please enter amount of files you want created (to overwrite deleted data)"; std::cin>>DesiredAmountOfFiles; for(FileNumber=0;FileNumber<DesiredAmountOfFiles;FileNumber++) { itoa(FileNumber, FileNum, 10); File=FileName+FileNum+FileType; std::ofstream a_file(File.c_str()); for(FileLines=0;FileLines<3000;FileLines++) { a_file<<"Secure Disk Cleanse. "; } a_file<<"This program was made by\nCharles Staal.\n"; a_file<<"130 Gregory Way\nCalverton,New York\n11933"; a_file.close(); } for(FileNumber=0;FileNumber<DesiredAmountOfFiles;FileNumber++) { itoa(FileNumber, FileNum, 10); File=FileName+FileNum+FileType; Delete=Del+File; system(Delete.c_str()); } std::cout<<"\n\nFinished"; std::cin.get(); } if(Option=="SFD") { std::cout<<"Please enter file path.\n"; getline(std::cin,Path,'\n'); std::cout<<"Please enter File name.\n"; getline(std::cin,File,'\n'); FilePath=Path+File; std::ofstream a_file(FilePath.c_str(), std::ios::trunc); for(FileLines=0;FileLines<3000;FileLines++) { a_file<<"Secure File Deletion "; } a_file<<"This program was made by\nCharles Staal.\n"; a_file<<"130 Gregory Way\nCalverton,New York\n11933"; a_file.close(); Delete=Del+File; system(Delete.c_str()); std::cin.get(); } std::cin.get(); return 0; }
itoa isn't standard, which is why I recommended stringstreams, but it will work on most platforms.
Yeah, I only want it to work on Windows.. Linux has built in tools for this I believe and I also used system() so itoa() isn't going to matter all that much.