BS Errors

This is a discussion on BS Errors within the C++ Programming forums, part of the General Programming Boards category; I don't see any errors in my code but I guess there is alot... I think most have to do ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    241

    BS Errors

    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.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    Step one if you are using the string class, #include <string>. After that, post the error messages and indicate the lines they refer to.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Quote Originally Posted by Daved
    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...

  4. #4
    Registered User
    Join Date
    Mar 2006
    Location
    IL
    Posts
    23
    You might want to try the using namespace std; statement so you don't have to keep typing std::*

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    >> 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.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    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
    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;
    }
    Oh and I use std:: because I feel I have more control over the program and it is more efficient.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    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.

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Is there no alternative to that? Because I think that will mess up my loops.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    It won't mess up your loops. There are alternatives, but they would behave the same way.

  10. #10
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Well, I ended up using iota()
    Code:
    #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;
    }
    ^_^ Happyhappyjoyjoy

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    itoa isn't standard, which is why I recommended stringstreams, but it will work on most platforms.

  12. #12
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 08:00 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 05:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21