Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Sun Dec 09, 2007 10:50 pm    Post subject: [C++] Reply with quote

i need help.
How do i make an ini file,
write and read text to it, ive been googling for 2 hours and it didnt help at all
Back to top
View user's profile Send private message AIM Address MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Dec 09, 2007 10:52 pm    Post subject: Reply with quote

The first entry I found on Google:
http://www.functionx.com/bcb/howto/inifile.htm
Back to top
View user's profile Send private message
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Sun Dec 09, 2007 10:54 pm    Post subject: Reply with quote

Well, i already seen that.
and i dont know what the "include" is
to use Tinifile or inifile.
Back to top
View user's profile Send private message AIM Address MSN Messenger
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Mon Dec 10, 2007 1:37 am    Post subject: Reply with quote

WritePrivateProfileString()
Code:

BOOL WINAPI WritePrivateProfileString(
  __in  LPCTSTR lpAppName,
  __in  LPCTSTR lpKeyName,
  __in  LPCTSTR lpString,
  __in  LPCTSTR lpFileName
);


lpAppName = Section Header
lpKeyName = Variable
lpString = Variable Value
lpFileName = location and name of ini

The ini would look something like this
Code:

[Section Header]
Variable=Variable Value


GetPrivateProfileString()
Code:

DWORD WINAPI GetPrivateProfileString(
  __in   LPCTSTR lpAppName,
  __in   LPCTSTR lpKeyName,
  __in   LPCTSTR lpDefault,
  __out  LPTSTR lpReturnedString,
  __in   DWORD nSize,
  __in   LPCTSTR lpFileName
);



lpAppName = Section Header
lpKeyName = Variable
lpDefault = if there was an error, it will return the character you set it to
lpReturnedString = returns the variable value
nSize = size in characters
lpFileName = location and name of INI

Here is an example of using both of them
Code:

#include <iostream>
using std::cout;
using std::endl;

#include <windows.h>

int main()
{
   char cDir[MAX_PATH] = { 0 };
   GetCurrentDirectory(MAX_PATH, cDir);
   lstrcat(cDir, "\\Test.ini");

   if   (WritePrivateProfileString("Something", "Value", "something", cDir))
   {
      cout << "INI was created at " << cDir << endl;

      char value[225] = { 0 };
      GetPrivateProfileString("Something", "Value", "", value, 225, cDir);
      cout << "The key value is " << value << endl;
   }
   else
      cout << "INI was not created" << endl;
   return 0;
}
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Dec 10, 2007 3:57 am    Post subject: Reply with quote

Heres a decent class that will do everything for you:
http://www.codeproject.com/KB/cpp/CIni.aspx

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Mon Dec 10, 2007 4:31 am    Post subject: Reply with quote

Code:
#include <iostream>
#include <fstream>

int main(int argc, char** argv)
{
   std::ofstream iniOut("inifile.ini");
   if(iniOut.is_open()) {
      iniOut << "Something=7" << std::endl;
      iniOut.close();
      std::cout << "Ini file written successfully." << std::endl;
   }
   else
      std::cout << "Problems w/ opening the file." << std::endl;

   return EXIT_SUCCESS;
}
No need for external libraries.
Back to top
View user's profile Send private message
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Mon Dec 10, 2007 11:43 am    Post subject: Reply with quote

Ok, i decided to use GetPrivateProfileInt, but how do i make it read a custom value?. Ie, ive seen examples of it seeing if the value is 100 , but i want it to retrieve a value from the ini and set it as an integer.
Back to top
View user's profile Send private message AIM Address MSN Messenger
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Mon Dec 10, 2007 3:05 pm    Post subject: Reply with quote

atoi will convert a string to an integer.
Code:

char cSomething[] = "100";
int iSomething = atoi(cSomething);
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Dec 11, 2007 5:48 am    Post subject: Reply with quote

atoi is bad for your health.

Code:
#include <iostream>
#include <string>
#include <sstream>

int main(int argc, char** argv)
{
   std::string sNumber("123");
   int iNumber;
   std::istringstream iss(sNumber);

   if( iss >> iNumber )
      std::cout << "iNumber == " << iNumber << std::endl;
   else
      std::cout << "Something weird happened." << std::endl;

   return EXIT_SUCCESS;
}
Code:
#include <iostream>
#include <boost/lexical_cast.hpp>

int main(int argc, char** argv)
{
   std::string sNumber("123");
   int iNumber;

   try {
      iNumber = boost::lexical_cast<int>(sNumber);
      std::cout << "iNumber == " << iNumber << std::endl;
   }
   catch(boost::bad_lexical_cast &) {
      std::cout << "Something weird happened." << std::endl;
   }

   return EXIT_SUCCESS;
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites