📄 testproject.cpp
字号:
// multimap_find.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
/* try to use substr
int main()
{
string str( " <Customer id=\"1024\" weight=\"3\">" );
basic_string<char>::size_type pos1,pos2;
cout << str << endl;
pos1 = str.find( '<' );
pos2 = str.find( ' ', pos1 );
cout << pos1<< ',' << pos2 << '\t'
<< '.'<<str.substr( pos1, pos2 - pos1 ) << '.'<< endl;
pos1 = str.find( "id", pos2 );
pos2 = str.find( ' ', pos1 ) ;
cout << pos1<< ',' << pos2 << '\t'
<< '.'<<str.substr( pos1, pos2 - pos1 ) << '.' << endl;
pos1 = str.find( "weight", pos2 );
pos2 = str.find( '>', pos1 ) ;
cout << pos1<< ',' << pos2 << '\t'
<< '.'<< str.substr( pos1, pos2 - pos1 ) << '.' <<endl;
cout << pos1<< ',' << pos2 << '\t'
<< '.'<<str.substr( pos1 ) << '.' << endl;
getch();
return true;
}*/
/* try to use multimap
int main( )
{
using namespace std;
multimap <int, int> m1;
multimap <int, int> :: const_iterator m1_AcIter, iter;
typedef pair <int, int> Int_Pair;
m1.insert ( Int_Pair ( 1, 10 ) );
m1.insert ( Int_Pair ( 2, 20 ) );
m1.insert ( Int_Pair ( 3, 20 ) );
m1.insert ( Int_Pair ( 3, 30 ) );
for( iter = m1.begin(); iter != m1.end(); ++iter ){
cout<< iter->first << '\t' << iter->second<<endl;
getch();
}
getch();
return true;
}
*/
/*
int main()
{
fstream projFile( "project.xml", ios_base::in | ios_base::out );
string proj("Aisa");
projFile.seekg( -15, ios_base::end );
projFile<<'<'<<proj<<'>'<<1025<<"</"<<proj<<'>'<<endl;
projFile<<"</Project_File>"<<endl;
return true;
}
*/
/* Try read and write file with C FILE type.
void readFile();
void writeFile( const string& buf, int pos );
int main()
{
string proj("America");
FILE* projFile;
//FILE* forwardPos;
basic_string <char>::iterator iter;
string buf;
int pos1,pos2;
char ch;
if( (projFile=fopen( "project.xml","r+" ))==NULL ){
cerr<<"open project define file error."<<endl;
return false;
}
while( (ch=fgetc(projFile))!=EOF ){
pos1 = ftell( projFile ) ;
if( ch=='<' ){
buf.clear();
while( (ch=fgetc(projFile))!='>' )
{ buf += ch; }
if( buf==proj ){
while( (ch=fgetc(projFile))!='<' ){ }
while( (ch=fgetc(projFile))!='>' ){ }
buf.clear();
while( (ch=fgetc(projFile))!=EOF )
{ buf += ch; }
pos2 = ftell( projFile );
/*
fseek( projFile, -(pos2-pos1+1), 1 );
for( iter=buf.begin(); iter!=buf.end(); iter++ ){
fputc( *iter, projFile );
}
fputc( EOF, projFile );
fputc( '\n', projFile );
fclose( projFile );
writeFile( buf, pos1 );
break;
}
}
}
readFile();
getch();
return true;
}
void writeFile( const string& buf, int pos )
{
basic_string<char>::const_iterator iter;
ofstream os;
os.open( "project.xml" );
os.seekp( pos );
for( iter=buf.begin(); iter!=buf.end(); iter++ )
{ os.put( *iter ); }
}
void readFile(){
char ch;
ifstream is;
is.open( "project.xml" );
while( is>>ch ){
cout<<ch;
}
}
*/
/* test read and write a file same time, false result. bad fstream.
void readFile( );
void writeFile( );
fstream fstr;
int main()
{
cout<<"write file:"<<endl;
writeFile();
cout<<"read file:"<<endl;
readFile();
cout<<"read file:"<<endl;
readFile();
getch();
return true;
}
void writeFile( )
{
fstr.open( "test.txt" ,ios::out );
fstr<<"Thank you.";
fstr.close();
}
void readFile( )
{
char ch;
fstr.open( "test.txt", ios::in );
while( fstr>>ch )
{ cout<< ch; }
cout<<endl;
fstr.close();
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -