file manipulation

This is a discussion on file manipulation within the C++ Programming forums, part of the General Programming Boards category; I am trying to write a program (internal assessment for those who know anything about IB) and I'm not sure ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    3

    Arrow file manipulation

    I am trying to write a program (internal assessment for those who know anything about IB) and I'm not sure how to read from files created.

    I have succesfully created a file which will hold user names/passwords and am able to add on the end with no problem. I just need to know how to check the file to see if the username exists when entered and if the password is the same as when first entered.

    any help would be greatly appreciated, even links to tutorials on the internet of how to do this with examples.

    Thanks,
    HB9/KC5ZFZ

  2. #2
    Unregistered
    Guest
    You can't manipulate data in the file while it is in the file. You have to read the file data into your program, manipulate it, then write it back to the file.

    Therefore:

    declare a container to hold data from file:
    search container for name entered;
    if name found compare password to listed;
    write container contents back to file if they were changed.

    If you are using c_style strings then you will need to use strcmp() or one of the related functions. If you are using a string class that has an overloaded == operator (eg STL string class), then you can do direct comparison of strings.

    Note: if your file is written using standard field sizes you mignt be able to write just the changed data rather than the entire container, but that is a bit more sophisticated than writing the entire contents of the contaier.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    93

    i guess...

    hmm i guess you could use <fstream.h>


    int main();
    {

    ifstream import_file("blah.txt"); //replace blah.txt with your file

    cout << "Enter Username";
    cin.getline(user_input);

    import_file >> a;

    while (check_username(a) == false && import_file !EOF)
    {
    import_file >> a;
    }

    cout << "User name and password found";

    getch();
    return 0;

    }


    //--------------FUNCTIONS----------\\



    bool check_username(AnsiString a);
    {
    if( strcomp(user_input, a) = 0)
    {
    return true;
    }
    else
    {
    return false;
    }
    }



    i dunno i wrote this up in like 5 secs without thinking.. don't know if this what your looking for or if this can help.. i'm trying to figure out file input myself....this only matches usernames but you could easily add code to match usernames and passwords...(probably small syntax errors in my code, i'm too lazy to read it)

    Plus i'm a begginner so beware

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 11:51 PM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

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