设置PSPad调用Mingw编译

2009年11月12日 16:04

设置->语法高亮->c/c++->编译程序:

编译程序:

D:\MinGW\bin\g++.exe

参数:

-Wall %Name%%Ext% -o %Name%.exe

默认目录:

%Dir%

编译之后执行:

cmd /K %Name%.exe

选上获得程序的输出结果

还可在规范中设置上help文件的路径

评论(0) 阅读(2555)

C++ 精确计算运行时间

2009年11月05日 03:50

最近在宿舍老是不能上网,非常郁闷……还是好好看书吧

做着实验,搜了半天,好歹找个看得懂了

#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
    int jingDu=10000000;
    LARGE_INTEGER frequency,nStartCounter,nStopCounter;
    QueryPerformanceFrequency(&frequency);

    QueryPerformanceCounter(&nStartCounter);

    for(int i=0; i< 100; i++)
        cout << i << endl;

    QueryPerformanceCounter(&nStopCounter);

    double time=((nStopCounter.QuadPart - nStartCounter.QuadPart) * jingDu)/frequency.QuadPart;

    cout << "i lives " << time/jingDu << " second" << endl;
//    TCHAR buffer[100];
//    wsprintf(buffer,"執行時間 %d millisecond ",time);
//    MessageBox(NULL,buffer,"計算時間",MB_OK);
}

评论(0) 阅读(1834)

C++ 自然归并排序

2009年10月25日 22:06

课本上没有源码,但看起来思路不错,于是自己写了个

    void NaturalMergeSort(T a[], int n)
    {
        T *ta = new T [n];//临时数组
        int b[n];//包含各有序子序列断点
        int lenb=0;
        b[lenb++]=-1;//b[0]始终指首
        for (int i=0; i<n-1 ; i++ )//分断点
            if(a[i]>a[i+1]) b[lenb++]=i;
        b[lenb++]=n-1;//指尾

        while(lenb>2)//不断合并
        {
            int i=0,newlenb=1;
            for (i=0; i<lenb-2; i+=2)
            {
                Merge(a, ta, b[i]+1, b[i+1], b[i+2]);//相邻的两个两个合并
                for (int j=b[i]; j<=b[i+2]; j++ )//拷回
                    a[j]=ta[j];
                b[newlenb++]=b[i+2];//b一定越来越小,所以可以重复利用
            }

            if(i==lenb-2) b[newlenb++]=b[lenb-1];//处理最后的孤点
            lenb=newlenb;
        }
    }

    void Merge(T c[], T d[], int l, int m, int r)
    {
        // Merge c[l:m]] and c[m:r] to d[l:r].
        int i = l,    // cursor for first segment
                j = m+1,  // cursor for second
                    k = l;    // cursor for result

        // merge until i or j exits its segment
        while ((i <= m) && (j <= r))
            if (c[i] <= c[j]) d[k++] = c[i++];
            else d[k++] = c[j++];

        // take care of left overs
        if (i > m) for (int q = j; q <= r; q++)
                d[k++] = c[q];
        else for (int q = i; q <= m; q++)
                d[k++] = c[q];
    }

 

评论(0) 阅读(2699)

boost filesystem 递归遍历目录

2009年10月10日 04:22

 

#include <iostream>
using std::cout;
using std::endl;
#include "boost/filesystem.hpp"
using namespace boost::filesystem;

int main()
{
    path mypath("F:/music");
    for (recursive_directory_iterator itr(mypath);
            itr!=recursive_directory_iterator(); ++itr)
        cout << itr->path().string()<<endl;
    return 0;
}

recursive_directory_iterator是递归迭代器,directory_iterator是非递归的。

评论(0) 阅读(3792)

boost filesystem 连接目标库

2009年10月10日 02:58

正在学概率论与数理统计,找个库算正态分布,于是找到了boost。感叹这东西实在是太强大了!

昨天看了看分布的部分,发现很简单很好用,因为只要include就可以了。

今天想试试filesystem却发现只include是不行的,还要连接静态库或动态库。

总结一下:

首先在网上搜到的关于库名的资料:

详见 more/getting_started/windows.html。
Release版
    动态Boost库的引用库
        单线程:              例:boost_filesystem-vc71-1_34.lib
        多线程:-mt           例:boost_filesystem-vc71-mt-1_34.lib
    静态Boost库
        使用动态CRT
            单线程:lib       例:libboost_filesystem-vc71-1_34.lib
            多线程:lib -mt   例:libboost_filesystem-vc71-mt-1_34.lib
        使用静态CRT
            单线程:lib -s    例:libboost_filesystem-vc71-s-1_34.lib
            多线程:lib -mt-s 例:libboost_filesystem-vc71-mt-s-1_34.lib
Debug版:加gd,g:用Debug版CRT,d:Debug版Boost。
如有错误,请指正。

Code::Blocks中项目 右键 构建选项 在 linked settings :: 链接库 中可以添加静态或动态链接库。

静态:

..\..\lib\boost_1_40_0\lib\libboost_system-mgw34-1_40.lib

..\..\lib\boost_1_40_0\lib\libboost_filesystem-mgw34.lib

动态:

..\..\lib\boost_1_40_0\lib\boost_system-mgw34-1_40.lib

..\..\lib\boost_1_40_0\lib\boost_filesystem-mgw34.lib

动态 还要把

boost_system-mgw34-1_40.dll

boost_filesystem-mgw34-1_40.dll

放到编译出的程序的目录下。

boost filesystem用法可见:http://www.ibm.com/developerworks/cn/aix/library/au-boostfs/

评论(0) 阅读(2488)