1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Storing information for later use in C++??

Discussion in 'Software Development' started by r3drock3t88, Jan 22, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. r3drock3t88

    r3drock3t88 Thread Starter

    Joined:
    Jan 12, 2007
    Messages:
    272
    Hey all, I was wondering if anyone could possibly lead me in the right direction here... what I want to do for example is have the console open up and ask the user for their name, they enter it and the program saves it so that next time they open the program their name will still be saved.

    Any help would be much appreciated, thank you in advance!:D
     
  2. AGCurry

    AGCurry

    Joined:
    Jun 15, 2005
    Messages:
    431
    Well, you have to save the name to a file. The program will check to see if there is a file existing; if there is, it will open and read the file; if not, the user will be prompted for his name.

    Obvious problem is: How do you make it work for multiple users?
     
  3. Chicon

    Chicon

    Joined:
    Jul 29, 2004
    Messages:
    6,650
    Multithreading and data synchronization in C++ !
     
  4. cpscdave

    cpscdave

    Joined:
    Feb 25, 2004
    Messages:
    444
    Why not store the information inside of a database. This probally would be the best solution. As my boss always tells me "DB code >>>> your code"
    :D
     
  5. AGCurry

    AGCurry

    Joined:
    Jun 15, 2005
    Messages:
    431
    How does the program know who you are once you've exited the program and restarted it?
    I don't know about Windows, but Unix has the getuid() function which would tell the program who you are...

    A bit of overkill, perhaps. What if you don't have a database?
     
  6. Chicon

    Chicon

    Joined:
    Jul 29, 2004
    Messages:
    6,650
    I guess there exist some Windows API's to get the user ID or the session ID in Visual C++.
    Such API exist in the Java servlet technology.
     
  7. GCDude

    GCDude

    Joined:
    Apr 1, 2005
    Messages:
    394
    from MSDN

    GetUserName - The GetUserName function retrieves the user name of the current thread. This is the name of the user currently logged onto the system.
     
  8. r3drock3t88

    r3drock3t88 Thread Starter

    Joined:
    Jan 12, 2007
    Messages:
    272
    wow lol, thanks for all of the quick responses... I assumed that someone would mention to get a database, but i dont want this to be a major project, just something for home use.

    this is what i found on cplusplus.com i believe it was,

    // basic file operations
    #include <iostream>
    #include <fstream>
    using namespace std;

    int main () {
    int num;
    ofstream myfile;
    myfile.open ("example.txt");

    myfile << "This text goes into example.txt";

    myfile.close();

    return 0;
    }

    but this code deosnt allow you to enter code to be put in the my file function, or atleast nto that i know of haha
     
  9. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/537457

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice