Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 21-24 of 24 total

print as hex

   1  
   2  const int val = 28;
   3  cout.setf(ios_base::hex, ios_base:showbase, ios_base::basefield);
   4  cout << val;


ref :stroustroup, c++ programming language, pg. 627

MFCでレジストリの代わりにINIファイルを使う

   1  
   2  #include <shlwapi.h>
   3  
   4  BOOL CMyApp::InitInstance()
   5  {
   6    // ... 
   7  
   8    TCHAR szIniPath[MAX_PATH];
   9    VERIFY(::GetModuleFileName(::AfxGetInstanceHandle(), szIniPath, MAX_PATH) != 0);
  10    VERIFY(::PathRenameExtension(szIniPath, _T(".ini")) != FALSE);
  11    ::free(static_cast<LPVOID>(const_cast<LPTSTR>(m_pszProfileName)));
  12    m_pszProfileName = ::_tcsdup(szIniPath);
  13  
  14    // ...
  15  
  16    return TRUE;
  17  }

Calling Python from Symbian C++

   1  
   2  CSPyInterpreter* it = CSPyInterpreter::NewInterpreterL();
   3  CleanupStack::PushL(it);
   4  PyEval_RestoreThread(PYTHON_TLS->thread_state);
   5  
   6  PyRun_SimpleString("open(r'c:\\foo.txt', 'w').write('hello')\n");
   7  
   8  PyEval_SaveThread();
   9  CleanupStack::PopAndDestroy(it);

From Nokia Forum

Convert string to anything

   1  template <class T> T
   2  fromString(const string &s) {
   3    T t;
   4    istringstream iss(s);
   5    iss >> t;
   6    return t;
   7  }


You can then convert numbers in strings to other types like this:

   1  double d = fromString<double>("10.2")
« Newer Snippets
Older Snippets »
Showing 21-24 of 24 total