Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

c++ - store number not i n file?

  • 07-02-2006 1:53pm
    #1
    Closed Accounts Posts: 1,061 ✭✭✭


    Is there any way in c++ to store a number, but not in a file.
    E.g I want to count the number of times the program is run.


Comments

  • Closed Accounts Posts: 7,346 ✭✭✭Rev Hellfire


    Try using your fingers.


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Or if you're on windows, in the registry.


  • Closed Accounts Posts: 7,346 ✭✭✭Rev Hellfire


    Put in a database, oracle do nice ones and should scale to meet the needs of your application, plus is not tied to a platform.


  • Closed Accounts Posts: 268 ✭✭UberNewb


    Try using your fingers.

    lol! :D

    If it is windows try using these :

    SetRegistryKey(_T("My Programs 1"));

    WriteProfileInt("Program Run", "Count", n);

    GetProfileInt("Program Run", "Count", 0);


  • Closed Accounts Posts: 1,061 ✭✭✭dawballz


    meh... not worth the hassle.. il just put it in a file./


  • Advertisement
  • Closed Accounts Posts: 268 ✭✭UberNewb


    dawballz wrote:
    meh... not worth the hassle.. il just put it in a file./

    :confused:


  • Registered Users, Registered Users 2 Posts: 2,082 ✭✭✭Tobias Greeshman


    You do realise its probably going to take more code to write to a file and read back from it, than save to the registry.
    main()
    {
      SetRegistryKey ( "Program" ) ;
      int i ;
      GetProfileInt ( "Program", "Count", &i ) ;
     
    
      //................ Rest of application
    
      // Application ending
      i++ ;
      WriteProfileInt ( "Program", "Count", i ) 
      return 0 ;
    }
    
    What could be simpler, in all fairness.


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Hell if you're going to be that lazy then just go with Rev's original suggestion.


  • Closed Accounts Posts: 1,061 ✭✭✭dawballz


    Hmmmm.. ok then, i might just go with the registry one..
    But I don't understand the code above..should Program be the name of my program?..

    If I want to check how many times the program was run, what do I do...?
    Is it just this line:
    GetProfileInt ( "Program", "Count", &i ) ;
    then say.. cout << i;
    ?

    What header file do i need?
    thanks,


  • Closed Accounts Posts: 7,346 ✭✭✭Rev Hellfire


    You can do it in one line if your users will help
    //
    // Launch notepad and get the users to add their name and the time into it
    WinExec("notepad.exe", 0);
    


    btw when's this project due by ?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,082 ✭✭✭Tobias Greeshman


    "Program" is whatever you want to call your project/programs key in the registry, call it whatever you want.

    windows.h should do it, look in MSDN, my god your lazy :eek:

    Yeah after GetProfileInt ( ) call, you have your information from the registry.


  • Closed Accounts Posts: 1,061 ✭✭✭dawballz


    You can do it in one line if your users will help
    //
    // Launch notepad and get the users to add their name and the time into it
    WinExec("notepad.exe", 0);
    


    btw when's this project due by ?

    Mid March.
    I think I don't really have to have the number of times the prog is run.
    All I really need is to know if it is the programs first time to be run, so what I am doing is creating a file. Then, for every run, it checks if the file is there.
    If the file is there, it is not the first time the program is ran, otherwise the program has been ran before...make sense?

    Thanks for your help..


Advertisement