25
2012
10

测试用c#操作mysql

 

原始数据:

25
2012
10

今天学习使用mysql遇到的问题和解决办法

安装到最后出现问题,无响应,那么不要紧,前面的安装成功了,只是没配置。关闭之后,直接命令开启服务,再使用。

 

18
2012
10

linux下练习 c++ 类库中list的特性、关联式容器共性介绍

code:

/*
库模版中 list 特性:
双向链表
增删:.push_front(element),.pop_front(),.remove(element)
不支持下标访问
除去重复:.unique() 相邻的重复元素只保留一个
排序:.sort(),默认用'<'号比较,自定义类型要重载运算符
倒置:.reverse()
转移:.aplice(pos,list2),.aplice(pos,list2,pos2),
 .aplice(pos,list2,pos2_begin,pos2_end)  
归并:.merge(list2)
*/
#include<iostream>
using namespace std;
#include<list>
#include<cassert>
#include "print.h"
bool mult3(int x,int y)//模3的余数从小到大
{
x%=3;
y%=3;
return x<y;
}
int main()
{
int a[7]={3,5,5,8,5,1,6};
int b[5]={5,7,9,2,4};
list<int> li(a,a+7),li2(b,b+5);
print(li.begin(),li.end());
li.unique();//可自定义判断相等的函数
print(li.begin(),li.end());
li.sort();//排序
li.unique();//去重
print(li.begin(),li.end());
li.reverse();//倒序
print(li.begin(),li.end());
li.splice(li.begin(),li2);//转移
print(li.begin(),li.end());
assert(li2.empty());//判断是否为空,为假时才报错
li.remove(5);//删除值为5的所有元素
print(li.begin(),li.end());
li.sort();li.unique();//去重
print(li.begin(),li.end());
li2.push_back(3);li2.push_back(5);
li2.push_back(9);li2.push_back(10);
print(li2.begin(),li2.end());
li.merge(li2);//将li2合并到li中
print(li.begin(),li.end());
b[3]=6;
li2.assign(b,b+5);
print(li2.begin(),li2.end());
li2.sort(greater<int>());//用'>'排序,从大到小
print(li2.begin(),li2.end());
li2.sort(mult3);//用自写规则排序,从小到大
print(li2.begin(),li2.end());
return 0;
}


18
2012
10

linux下练习 c++ 容器的deque的特性

code:

/*
deque特性
下标:.operator[](i)不检查越界,.at(i) 
删除:.pop_front(),.pop_back()
*/
#include<iostream>
using namespace std;
#include<deque>
#include "print.h"
int main()
{
deque<char> dq;
dq.push_back('c');
dq.push_back('d');
dq.push_back('e');
dq.push_back('f');
print(dq.begin(),dq.end());
dq[1]='t';//把 d 改为 t
for(int i=0;i<dq.size();i++)
cout<<dq[i]<<' ';
cout<<endl;
dq.pop_back();//删除最后一个
dq.pop_front();//删除第一个
print(dq.begin(),dq.end());
return 0;
}


16
2012
10

C#练习Array.Sort函数列出所有的进程与模块

.Net Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Collections;
namespace ICompare测试
{
    class Program
    {
        static void Main(string[] args)
        {
            Process[] allprocess = Process.GetProcesses();//所有运行的进程
            SortByProcessName cmpproname=new SortByProcessName();
            SortByModuleName cmpmodulename=new SortByModuleName();
            Array.Sort(allprocess, cmpproname);
            foreach (Process p in allprocess)
            {


15
2012
10

linux下练习 c++ 容器的vector的特性

//vector.cpp

/*
vector的特性
当前容量:.capacity()
约定容量:.reserve()
下标:.operator[](i) ,.at(i) 越界抛出异常
*/
#include<iostream>
using namespace std;
#include<vector>
#include<exception>
#include<typeinfo>
#include "print.h"
void print(const vector< vector<int> >& v)//相当于二维数组
{
for(int i=0;i<v.size();i++)
{
for(int j=0;j<v[i].size();j++)
cout<<v[i][j]<<' ';
cout<<endl;
}
}
int main()
{
vector<double> vt,vt2;//默认容量成倍增长,4,8,16……
for(int i=1;i<10;i++)
{
vt.push_back(i+0.2);
cout<<vt.size()<<'/'<<vt.capacity()<<' ';
}
cout<<endl;
vt2.reserve(9);//只分配这么多,不成倍增长
for(int i=1;i<10;i++)
{
vt2.push_back(i+0.3);
cout<<vt2.size()<<'/'<<vt2.capacity()<<' ';
}
cout<<endl;
vt.at(3)=30.50;//修改值
vt[4]=40.70;
try
{
for(int i=0;i<vt.size();i++)
cout<<vt.at(i)<<' ';
cout<<endl;
}
catch(exception& e)
{
cout<<"\n异常:"<<e.what()<<endl;
cout<<"类型:"<<typeid(e).name()<<endl;
}
int m=3,n=5;
vector< vector<int> > vvi(m,vector<int>(n));//二维vector
vvi.resize(m+3);
vvi[1].assign(9,3);
vvi[5].assign(4,5);
print(vvi);
}
/*
template <typename T>
void show(T a[],int n);
template <typename T>
void show(const vector<T>& vt);
*/


15
2012
10

linux下练习 c++ 序列容器的使用

code:

// sequence.cpp 
/*
序列式容器:vector,deque,list
插入:.insert(position,n,element), .insert(position,pos_begin,pos_end)
赋值:.assign(n,element), .assign(pos_begin,pos_end)
调整:.resize(n,element=value)
首尾:.front(),.back()
增删:.push_back(element), .pop_back()----删除,返回void
*/
#include <iostream>
#include <deque>
#include <string>
#include "print.h"
using namespace std;
int main()
{
deque<string> ds;
ds.push_back("zhang");//增加
ds.push_back("pu");
ds.push_back("yang");
ds.push_back("xie");
ds.insert(ds.begin()+1,1,"wang");//插入
string s1[3]={"liao","hu","liu"};
ds.insert(----ds.end(),s1,s1+3);
print(ds.begin(),ds.end(),',');
ds.pop_back(); //删除最后一个
ds.pop_back();
print(ds.begin(),ds.end(),',');
ds.resize(10,"pkm");//大小设为10,后面用pkm填充
print(ds.begin(),ds.end(),',');
ds.assign(5,"kkkkk");//5个,都为kkkkk
print(ds.begin(),ds.end(),',');
return 0;
}


15
2012
10

linux下练习 c++ 普通容器的使用

code:

/*
迭代器
.begin(),.end() ,.rbegin() , .rend()
插入:.insert(position,element)
删除:.erase(position),.erase(pos_begin,pos_end)
清除:.clear()
大小:.size(), .max_size(), .empty()
交换:.swap(c2) , swap(c1,c2)
运算符:=,>,<,>=,<=,==,!=
*/
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
#ifndef print_fun
#define print_fun
template<typename T>
///显示序列数据
void print(T b,T e)
{
bool isExit=false;
while (b!=e)
{
cout<<*b++<<' ';
isExit=true;
}
if(isExit) cout<<endl;
}
#endif
int main()
{
int a[5]={44,33,55,66,11};
vector<int> vi(a,a+5);//用数组初始化一个迭代器vi
cout<<vi.size()<<endl;
sort(vi.begin(),vi.end());//元素排序
vector<int>::iterator b= vi.begin();
print(vi.begin(),vi.end());//正向迭代器
print(a,a+5);
print(vi.rbegin(),vi.rend());//反向迭代器
vi.insert(vi.begin()+1,48);//插入到第2
vi.insert(vi.end(),49);//插入到最后
vi.insert(vi.end()-1,57);
print(vi.begin(),vi.end());
vi.erase(vi.end()-1);//删除最后一个
print(vi.begin(),vi.end());
vi.erase(vi.begin()+2,vi.end()-2);//删除一个区间
print(vi.begin(),vi.end());
vector<int> v2(a,a+5);
vi.swap(v2);//vi与v2交换
print(vi.begin(),vi.end());
vi.swap(v2);//vi再与v2交换回去 
print(vi.begin(),vi.end());
vi.clear();//清空容器
cout<<vi.size()<<endl;
return 0;
}


14
2012
10

linux下练习 c++ 库函数排序使用举例

code:

//使用库函数排序举例
#include <iostream>
#include <string>
#include <algorithm>//内有排序库函数
using namespace std;
#ifndef person_h_1  //预定义指令
#define person_h_1
class person
{
public:
person(const char* name,int age):name(name),age(age){}//构造函数
friend ostream& operator<<(ostream& o,const person& p)//重载输出
{
return o<<p.name<<":"<<p.age<<' ';
}
friend bool operator <(const person& a,const person& b)//重载小于
{
return a.age<b.age;
}
private:
string name;
int age;
};
#endif
template<typename T>
void print(T b,T e)//输出数组内容
{
bool isnull=true;
while (b!=e)
{
cout<<*b++<<' ';
isnull=false;
}
if(isnull==false) cout<<endl;
}
int main()
{
int a[6]={5,8,6,4,9,1};
double b[4]={4.4,3.2,6.7,1.2};
string c[5]={"yeah","are","you","people","good"};
person p[3]={person("ppp",23),person("kkk",21),person("mmm",20)};
sort(a,a+6);//排序
sort(b,b+4);
sort(c,c+5);
sort(p,p+3);
print(a,a+6);//输出
print(b,b+4);
print(c,c+5);
print(p,p+3);
}


13
2012
10

linux下练习 c++ 函数模版例子

code:

//函数模版使用
//函数模版标准不支持参数默认值
#include<iostream>
#include<cstring>
using namespace std;
template <typename T>
void sort(T* a,int n)//普通冒泡排序
{
bool changed;
do
{
changed=false;
for(int i=1;i<n;i++)
{
if(a[i]<a[i-1])
{
swap(a[i],a[i-1]);
changed=true;
}
}
--n;
}
while(changed);
}
template <>//模版特化
void sort(const char* a[],int n)//普通冒泡排序
{
bool changed;
do
{
changed=false;
for(int i=1;i<n;i++)
{
if(strcmp(a[i],a[i-1])<0)
{
swap(a[i],a[i-1]);
changed=true;
}
}
--n;
}
while(changed);
}
//template <typename T>
//void show(T t[],int n)
template <typename T,int n>
void show(T(&t)[n])
{
//int n=sizeof(t)/sizeof(t[0]);//算出t的个数
for(int i=0;i<n;i++)
cout<<t[i]<<' ';
cout<<endl;
}
template <typename T>
void show(T t)
{
cout<<t<<endl;
}
int main()
{
int a[5]={6,7,8,3,2};
sort(a,5);//函数模版会自动匹配,不需要显式指定类型
show(a);
double d=12.345;
show(d);
char c[5]={'b','f','k','d','a'};
sort(c,5);
show(c);
const char* ca[3]={"fc","ca","ab"};
sort(ca,3);
show(ca);
return 0;
}