Read And write string from file (code)

Category: C++ Questions    |    12 views    |    Add a Comment
I want to read and write string from file,
- Dont want to overwrite on the existing file
- Where to put the read file code as in Constructor if file is not created then it will generate error.
help me to solve this issue.

class Security{
private:
        Map<string>password;        
public:        
        Security(){
                ifstream infile;
                infile.open("pro.txt");
                int i = 0;
                int index = 0;
                int index2 = 0;
                if(infile.fail())Error("Can't read the Data file ");
                while(true){
                        string line;
                        getline(infile,line);
                        if(infile.fail()) break;                        
                        index = line.find('@',i);
                        index2 = line.find('=',i);
                        string key = line.substr(index+1,index2-index-1);
                        string value = line.substr(index2+1,line.length());
                        password.add(key,value);
                        i++;                        
                }
                infile.close();
        }
        bool isValidPassword(string login,string pass);
        bool setPassword(string login,string pass);
};

bool Security::setPassword(string login,string pass){
        if(password.isEmpty()){
                password.add(ConvertToUpperCase(login),pass);                                
                ofstream out("pro.txt");
                if(!out)Error("Can't Write Date to File " );
                        cout << "after adding " <<  password.isEmpty() << endl;
                  double num = 100.45;
                  string temp = login + "=" + pass;
                  out.write((char *) &num,sizeof(double));
                  out.write(temp.c_str(),temp.length());
                  out.close();
        }        
        return true;                
}

bool Security::isValidPassword(string login,string pass){
        if(password.containsKey(ConvertToUpperCase(login))){
                return password.getValue(ConvertToUpperCase(login))==pass?true:false;
        }
        return false;
}

Share/Save/Bookmark

  • No Related Post

 

Hiding Implimentation from others, How!

Category: C++ Questions    |    15 views    |    Add a Comment
Suppose i have a class called Vector3

methods and attributes are defined in Vce.h file,
methods of this class are implemeted in Vec.cpp file,

now i want to distribute this class to my other xxx(what so ever),

What i want:
1.Allow them to see what methods and attributes are available in this class.
2. Allow them to use methods of these class into their code

What i don’t want:
1. I don’t want to allow them to see how methods are implemeted.
2. Dont want to allow them to edit this class, but they can enhance the class compability by making their own derived classes using this class as a base.

How to achive this??
I have listen some what that dll and lib files are used for this kinda stuff but don’t know how?

Any tutorial, or article related this plz put the link here.

Thanks.
Muhammad Ahmed

Share/Save/Bookmark

  • No Related Post

 

Returning all installed network printers

Category: C++ Questions    |    12 views    |    Add a Comment
Hey,
I am curious about making an application that will show current printers that are installed on the computer, will be windows XP, and at first returning them back for the user to see in command prompt.

Although I am unable to find out how I can check to see what printers are installed in the system, and a poke in the right direction would be appriciated, is there a library or API for this?

Sorry for what is probably a very easy question, worded incredibly badly.
Sky_Blue

Share/Save/Bookmark

  • No Related Post

 

Help needed in appending the file from beginning

Category: C++ Questions    |    14 views    |    Add a Comment
Hi,
I am making a program in which i need to append the file from the beginning. so i am opening the file like this
wFile.open("sat.txt",ios::ate| ios::out | ios::in);
moving the pointer to the beginning
wFile.seekp(0,ios_base::beg);

but when i try add data it is overwriting the data. Is there any way that it doesn’t overwrite the data.
Thanks for the help

Share/Save/Bookmark

  • No Related Post