// test.cpp : Defines the entry point for the console application.
//
/*
#include "stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;int _tmain(int argc, _TCHAR* argv[])
{
fstream file("d:\ttt.txt");string str = "1234";
file << str;string str1;
file >> str1;cout << str1;
}
*///template<class T>
#include "stdafx.h"/*
#include <iostream>
#include <fstream>
#include<string>
using namespace std;//C++写文件和读文件
int main()
{
ofstream out("D:\\out.txt");
if (out.is_open())
{
out << "This is a line.\n";
out << "This is another line.\n";
out.close();
}
//out.flush();
ifstream in("D:\\out1.txt");
if (!in.is_open())
{
cout << "open failed\n";
return -1;
}
while(!in.eof())
{
string str;
getline(in, str);//包含头文件 string
cout << str<<endl;
}in.close();
return 0;
}
*///函数指针
//int (*pFun)(int i ,int j);/*
#include<iostream>#include<vector>
#include<cstdlib>
using namespace std;
int main()
{
vector<int> vec;
//vec.resize(5);
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
for (int i = 1; i < 8; ++i)
{
vec.push_back(i);cout<<"size: " << vec.size() << " " <<"capacity "<< vec.capacity() << endl;
}//cout << vec.size() << " " << vec.capacity() << endl;
//vec.push_back(6);
//cout<<"After push " << vec.size()<<" " <<vec.capacity()<<endl;
}
*//*
//函数指针
int(*pFun)(void);typedef int(*pFun)(int, int);
#include <windows.h>
#include <iostream>
using namespace std;
typedef int(*AddFunc)(int a, int b);
int main(int argc, char *argv[])
{
HMODULE hDll = LoadLibrary("DLLDemo1.dll");
if (hDll != NULL)
{
AddFunc add = (AddFunc)GetProcAddress(hDll, "Add");
if (add != NULL)
{
cout << add(2, 3) << endl;
}
FreeLibrary(hDll);
}
}
*/#include<iostream>
#include<string.h>
#include<memory.h>
using namespace std;struct Node
{
int nData;
Node *pNext;Node()
{
nData = 0;
pNext = NULL;
}
};
int Insert(Node *pNode, int val)
{
Node * p1 = pNode->pNext;
Node * p2 = p1->pNext;
while (p2->nData<val)
{
pNode++;
p1 = pNode->pNext;
if (p1->pNext)
{
p2 = p1->pNext;
}
}
Node *pNew = new Node();p1->pNext = pNew;
pNew->pNext = p2;return 0;
}struct MyStruct
{
int a;
char b[5];
};void test(char **p)
{
static char s_Array[] = "test";
*p = s_Array;
}typedef int(*PFun)(int, int);
int add(int a, int b)
{
return a + b;
}int main()
{
/*
int i = 4;
i <<= 3;
cout << "----i " <<i;
*/
/*
//sizeof和strlen求字符串长度,strlen求得的大小不包含'\0',sizeof包含'\0'
char *p = "Hello World";
int n = sizeof(p);
int nLength = strlen(p);cout << "sizeof p:" << n << endl;
cout << "strlen:" << nLength<<endl;char strArray[] = "Hello World";
int nn = sizeof(strArray);
int nLen = strlen(strArray);cout << "sizeof Array:" << nn << endl;
cout << "strlen Array:" << nLen << endl;
*/
/*
//sizeof对指针和结构体求字节数
MyStruct *pMyStruct = (MyStruct *)malloc(sizeof(MyStruct));
int n = sizeof(pMyStruct);
int nn = sizeof(*pMyStruct);
int nnn = sizeof(MyStruct);memset(pMyStruct, 0, nn);
//memset_s(pMyStruct, nn,0,nn);
cout << "sizeof *pMyStruct: " <<n<<"\n" ;
cout << "sizeof (*pMyStruct): " << nn << "\n";
cout << "sizeof MyStruct: " << nnn << "\n";
*//*
//二级指针用法
char *pp = new char[20];test(&pp);
*/
/*
//函数指针的用法
PFun pFun = add;
int a = pFun(1, 2);
int aa = (*pFun)(1, 2);
cout<<"<pFun(1, 2)=: "<<a<<endl;
cout << "(*pFun)(1,2)=: " <<aa<<endl;
*/
}