我想在特定点获得CPU周期.我在这一点上使用这个功能:
static __inline__ unsigned long long rdtsc(void)
{
unsigned long long int x;
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
return x;
}
Run Code Online (Sandbox Code Playgroud)
问题是它总是返回一个增加的数字(在每次运行中).就好像它指的是绝对时间.
我错误地使用了这些功能吗?
我想减去两个gettimeofday实例,并以毫秒为单位显示答案.
这个想法是:
static struct timeval tv;
gettimeofday(&tv, NULL);
static struct timeval tv2;
gettimeofday(&tv2, NULL);
static struct timeval tv3=tv2-tv;
Run Code Online (Sandbox Code Playgroud)
然后将'tv3'转换为毫秒分辨率.
我正试图在文件中获取部分文本.我用过"ifstream":
#include <fstream>
void func(){
char *myString;
ifstream infile;
infile.open("/proc/cpuinfo");
while (infile >> myString){
if (!strcmp(myString,"MHz"))
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到一个"分段错误".有谁知道为什么?
我有下一个代码:
std::string line;
std::ifstream myfile ("text.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
std::cout << line << std::endl;
}
myfile.close();
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点,并使用char*而不是字符串?
为什么圆形"14718.5084"到14718.5?有没有办法防止这种情况(即得到整数14718.5084)?
码:
double latitude=atof("14718.5084");
std::cout <<"latitude test "<<latitude<< "\n";
Run Code Online (Sandbox Code Playgroud)
输出是:
latitude test 14718.5
Run Code Online (Sandbox Code Playgroud)
谢谢