随笔:78 文章:7 评论:38 引用:0
C++博客 首页 发新随笔
发新文章 联系 聚合管理

http://woodpecker.org.cn/abyteofpython_cn/chinese/ch03s02.html
简明 Python 教程
这里面用的2.x的版本,所以如果你用的是3.x的版本,语法会有变化。
print ‘hello world' 应该写成 print('hello world')
posted @ 2011-07-28 10:30 未央 阅读(304) | 评论 (1)编辑 收藏
 
内存写入冲突。程序文件夹拷贝时有重名的文件,然后我点了取消,后来,再运行原程序,就出现上述错误,调试时发现该调用A函数的时候,程序却莫名其妙的调用了另一个函数。
虽然不知道具体问题出在哪儿,但是把工程文件夹里的debug文件夹删掉后重新编译运行就ok了。 路过的大虾知道原因的请指点,谢谢。
posted @ 2011-07-12 08:48 未央 阅读(3863) | 评论 (1)编辑 收藏
 
指针常量,int* const p; 这个指针是常量,所以指针指向的地址是不变的,但是地址里的内容可以变;
常量指针,const int *p; 指向的是常量,所以*p不能变,但是p可以指向另一个常量。
例如:
const int a = 5;
int b,c;
const int *p = a;
int * const p2 = b;
*p = 6; //错误
p2 =&c //错误

thanks hadn't 
posted @ 2011-06-19 18:29 未央 阅读(221) | 评论 (0)编辑 收藏
 
string str;
str.c_str(); str.data();两种方法都可以将string转换成char*,但必须是const char*。所以需要进一步转化成非const的char*.

string sname;
const char *cname=sname.c_str();
char ccname[500];
strcpy(ccname, cname);
posted @ 2011-06-09 10:31 未央 阅读(1940) | 评论 (1)编辑 收藏
 
VS2008升级方法

把90天试用版改为正式版,二种方法:
1. 把Setup\setup.sdb文件中的
    [Product Key]
    T2CRQGDKBVW7KJR8C6CKXMW3D
  改成
    [Product Key]
    PYHYPWXB3BB2CCMV9DX9VDY8T
据说Setup这个文件夹在VS的安装前的软件包的目录下,我没有试过。
2.安装完成后,在“控制面板”中启动“添加删除程序”,选中Vs2008 
输入序列号:PYHYP-WXB3B-B2CCM-V9DX9-VDY8T

如果没有输入序列号的文本框,需要下载一个补丁:

VS2008中英文正式版序列号
1.Visual Studio 2008 Professional Edition:
XMQ2Y-4T3V6-XJ48Y-D3K2V-6C4WT
2.Visual Studio 2008 Team Test Load Agent:
WPX3J-BXC3W-BPYWP-PJ8CM-F7M8T
3.Visual Studio 2008 Team System:
PYHYP-WXB3B-B2CCM-V9DX9-VDY8T
4.Visual Studio 2008 Team Foundation Server:
WPDW8-M962C-VJX9M-HQB4Q-JVTDM

posted @ 2011-06-07 13:52 未央 阅读(1052) | 评论 (1)编辑 收藏
 
    FILE *pFile;
    pFile 
= fopen("D:\\VisFiles\\TaoBao_data\\taobao\\brand_info_bj","r");  //路径要双斜线啊!
    
if(pFile!=NULL)
        printf(
"yes!\n");
    
else
        printf(
"no!\n");

posted @ 2011-04-14 14:52 未央 阅读(783) | 评论 (1)编辑 收藏
 
如下设置:
工具->选项->projects->C/C++目录->分别在:可执行文件,包含文件,库文件,源文件中填加
C:\QT\4.0.0\bin C:\QT\4.0.0\include C:\QT\4.0.0\lib C:\QT\4.0.0\src->确定

在WINDOWS环境变量中设置了C:\QT\4.0.0\bin C:\QT\4.0.0\include
posted @ 2011-03-16 17:10 未央 阅读(2881) | 评论 (1)编辑 收藏
 
【转】Qt中将QString转换为char *或者相反

1.将QString转换为std::string,可以通过QString的成员函数toStdString()

QString Qstr="123";std::string str=Qstr.toStdString();

2.将QString转换为char *或者相反

直接转换不行,因为QString没有提供直接的成员函数,但是可以通过QByteArray中转一下,例如:
int main(int argc, char **argv)
{
     QApplication app(argc, argv);
     QString str1 = "Test";
     QByteArray ba = str1.toLatin1();
     const char *c_str2 = ba.data();
     printf("str2: %s", c_str2);
     return app.exec();    
}

还有其他多种方法:

方法一 -----------------------------------------
#define G2U(s) ( QTextCodec::codecForName("GBK")->toUnicode(s) )
#define U2G(s) ( QTextCodec::codecForName("GBK")->fromUnicode(s) )

QString str;
QCString cstr;

str = G2U("中文输入");
cstr = U2G(str);

QCString有这样一个重载运算符
operator const char * () const

可以这样
printf("%s\n", (const char*) cstr);
或是copy出来
char buf[1024];
strcpy(buf, (const char*) cstr);

方法二 -----------------------------------------

如果是中文系统 直接用   (const char*) str.local8Bit()
例如
printf("%s", (const char*) str.local8Bit());

str是一个QString

方法三 -----------------------------------------
char str[64];
QTextCodec *textcod = QTextCodec::codecForName("GBK");
        QCString string1 = textcod ->fromUnicode(listbox1->currentText());
        strcpy(str,string1);

QString和Std::string

从char*到 QString可以从fromLocal8Bit()转化std::string有c_str()的函数使再转化为char*QString有toAscii()记不清了


你可以看看.


又是我的粗心酿成大错,我重新查看了一下Qt文档,原来Qt可以直接从std::wstring产生一个QString,用QString::fromStdWString(const std::wstring &)这个静态成员函数即可。我试了试用std::string的c_str()返回的char *构造的QString不能再保存原先的中文信息,而用std::wstring构造的QString则可以用qDebug()输出原先的中文信息GB编码与UTF8编码的转换在主函数app后加上这句:

QUOTE:

QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB18030"));

然后是从UTF8编码到GB编码的字符串转换方法:

QUOTE:


QString Utf8_To_GB(QString strText)
{
    return QString::fromUtf8(strText.toLocal8Bit().data());
}

至于从GB到UTF8,那大家就经常用了:

QUOTE:

QString GB_To_Utf8(char *strText)
{
    return QString::fromLocal8Bit(strText);
}

posted @ 2011-03-16 12:33 未央 阅读(13757) | 评论 (0)编辑 收藏
 

用的glut32.dll的版本太低了,编译用的版本与运行时的版本不一致。

Ok,网上下载了一个新版的glut32.dll替换到system32目录下,问题解决.

posted @ 2011-03-14 20:19 未央 阅读(1369) | 评论 (0)编辑 收藏
 
clock_t start0, finish0;
double duration0;
start0 = clock();
  finish0 = clock();
duration0 = (double)(finish0-start0)/CLOCKS_PER_SEC;
posted @ 2011-03-09 14:51 未央 阅读(322) | 评论 (0)编辑 收藏
仅列出标题
共8页: 1 2 3 4 5 6 7 8 
CALENDER
<2010年12月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(6)

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜


Powered By: 博客园
模板提供沪江博客