Onega

a lot of VC++ posts, a few C# posts, and some miscellaneous stuff

Wednesday, January 26, 2005

boost tokenizer

    {

        using namespace boost;

        typedef std::basic_string<TCHAR> tchar_string;

        tchar_string string_cmdline = GetCommandLine();

        //    typedef boost::tokenizer<boost::char_separator<TCHAR>,

        //        tchar_string::const_iterator,tchar_string > tokenizer;

        typedef boost::tokenizer<boost::escaped_list_separator<TCHAR>,

            tchar_string::const_iterator,tchar_string > tokenizer;

        boost::escaped_list_separator<TCHAR> sep( _T('`'), _T(' '), _T('\"'));

        tokenizer tokens(string_cmdline, sep);

        tokenizer::iterator tok_iter = tokens.begin();        //error

        for (tok_iter = tokens.begin();    

        tok_iter !=  tokens.end();    

        ++tok_iter)

        {        

            std::cout<< *tok_iter <<std::endl;        

        }

    }

    {

        using namespace boost;

        typedef std::basic_string<TCHAR> tchar_string;

        tchar_string string_cmdline = GetCommandLine();

        //    typedef boost::tokenizer<boost::char_separator<TCHAR>,

        //        tchar_string::const_iterator,tchar_string > tokenizer;

        typedef boost::tokenizer<boost::escaped_list_separator<TCHAR>,

            tchar_string::const_iterator,tchar_string > mytokenizer;

        boost::escaped_list_separator<TCHAR> sep( _T('`'), _T(' '), _T('\"'));

        mytokenizer tokens(string_cmdline, sep);

        mytokenizer::iterator tok_iter = tokens.begin();    //OK    

        for (tok_iter = tokens.begin();    

        tok_iter !=  tokens.end();    

        ++tok_iter)

        {        

            std::cout<< *tok_iter <<std::endl;        

        }

        

    }

Tuesday, January 25, 2005

set breakpoint at run time

set breakpoint at run time:
run in debug mode,
bring up break points dialog ( edit->breakpoints... (alt+F9) )
click the last empty row of breakpoints list,
in the break at input box, enter
{,m:\onega\test\mycontrol\testcode.cpp,} .133

Monday, January 17, 2005

restore database with osql.exe

osql.exe needs absolute path to the backup file.
osql -S "cn-040320" -U "sa" -P "sa" -Q "USE master RESTORE DATABASE [2005test] FROM DISK ='C:\Program Files\Microsoft SQL Server\80\Tools\Binn\2000RT_bk.mdf'"

Thursday, January 13, 2005

gSOAP and C# webservice

char data[2];
data[0] = '\4';
data[1] = 0;
bad request error when sending this data to web service.
use byte data is ok.

Tuesday, January 11, 2005

#include brings too many dependencies

20050111, I have included one more header to an existing header file, unfortunately this file is used by another project. That project complains loudly for unresovled link problem. At last it is fixed by conditional compile(does not include it if this header file is used in other project).

#ifndef xxxx
#include my_new_header
#endif

Monday, January 10, 2005

#endif hides code at the same line

#ifndef __TFUNCTION__
LPCTSTR __TFUNCTION__ = _T("OnApply");
#endif if( a==b) // the if clause would be ignored!!!

Friday, January 07, 2005

ambiguous call of min(...)

use std::min

Wednesday, January 05, 2005

tstring ToString(boost::posix_time::ptime &time_data)


tstring ToString(boost::posix_time::ptime &time_data)
{
/*
time to yyyymmdd-hhmmss
//test code:
boost::posix_time::ptime timestamp = boost::posix_time::second_clock::local_time(); ;
std::cout<< ToString(timestamp) <<std::endl;
*/
std::basic_stringstream<TCHAR> ts;
ts<<boost::gregorian::to_iso_string(time_data.date()) <<_T("-")
<< std::setw(2)<<std::setfill(_T('0')) << time_data.time_of_day().hours();
ts<<std::setw(2)<<std::setfill(_T('0')) <<time_data.time_of_day().minutes();
ts<<std::setw(2)<<std::setfill(_T('0'))<<time_data.time_of_day().seconds();
return ts.str();
}