C文件操作与fstream读取文本文件的效率比较
这几天由于要读取较大的文本文件,所以就比较了一下两者之间的效率问题。 所要读取的文本文件结构为每行由5个数组成,int int int float int,测试的文件有33W行,大小为9M。现在要将其读到一个cube结构体里面去,结构体有5个成员变量与之对应。 两种操作的代码如下 start = clock();
while(1)
{
fscanf(fp,"%d %d %d %f %d",&tmpcube.x,&tmpcube.y,&tmpcube.z,&tmpcube.temp,&tmpcube.type);
cubes.push_back(tmpcube);
if (tmpcube.type == -1)
break;
}
end = clock(); start = clock();
while(1)
{
fp>>tmpcube.x>>tmpcube.y>>tmpcube.z>>tmpcube.temp>>tmpcube.type;
cubes.push_back(tmpcube);
if (tmpcube.type == -1)
break;
}
end = clock(); 最后在我的电脑(AMD4000+)上运行得到的结果为前者960ms左右 后者2400+ms
相关文档:
VB
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = i1
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
MSComm1.InBufferCount = 0
& ......
Delphi 与 C/C++ 数据类型对照表
Delphi数据类型C/C++
ShorInt
8位有符号整数
char
Byte
8位无符号整数
BYTE,unsigned short
SmallInt
16位有符号整数
short
Word
16位无符号整数
unsigned short
Integer,LongInt
32位有符号整数
int,long
Cardinal,LongWord/DWORD
32位无符号整数
unsigned long
Int6 ......
C中如何调用C++函数?
前阵子被问及一个在C中如何调用C++函数的问题,当时简单回答是将函数用extern "C"声明,当被问及如何将类内成员函数声明时,一时语塞,后来网上查了下,网上有一翻译C++之父的文章可以作为解答,遂拿来Mark一下。
将 C++ 函数声明为``extern "C"''(在你的 C++ 代码里做这个声明), ......
#include <stdio.h>
#include <string.h>
/*
* decode encd with URL, the result saved to decd.
* return point to be decoded string.
* auth: baisoo email:baisoo@msn.com
*/
char *decode( char *encd, char decd[] );
int main( int argc, char *argv[] )
{
if( argc < ......
char dec2hexChar(short int n) {
if ( 0 <= n && n <= 9 ) {
return char( short('0') + n );
} else if ( 10 <= n && n <= 15 ) {
return char( short('A') + n - 10 );
} else {
return char(0);
}
}
short int h ......