为了好奇,我试图读取标志寄存器并以一种很好的方式将其打印出来.
我已经尝试使用gcc的asm关键字阅读它,但我无法让它工作.任何提示如何做到这一点?我正在运行Intel Core 2 Duo和Mac OS X.以下代码就是我所拥有的.我希望能告诉我是否发生溢出:
#include <stdio.h>
int main (void){
int a=10, b=0, bold=0;
printf("%d\n",b);
while(1){
a++;
__asm__ ("pushf\n\t"
"movl 4(%%esp), %%eax\n\t"
"movl %%eax , %0\n\t"
:"=r"(b)
:
:"%eax"
);
if(b!=bold){
printf("register changed \n %d\t to\t %d",bold , b);
}
bold = b;
}
}
Run Code Online (Sandbox Code Playgroud)
这给出了分段错误.当我运行gdb时,我得到了这个:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x000000005fbfee5c
0x0000000100000eaf in main () at asm.c:9
9 asm ("pushf \n\t"
Run Code Online (Sandbox Code Playgroud) 嗨,我有一个Boost线程,应该返回一个双.该函数如下所示:
void analyser::findup(const double startwl, const double max, double &myret){
this->data.begin();
for(int i = (int)data.size() ; i >= 0;i--){
if(this->data[i].lambda > startwl){
if(this->data[i].db >= (max-30)) {
myret = this->data[i+1].lambda;
std::cout <<"in thread " << myret << std::endl;
return;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
此函数由另一个函数调用:
void analyser::start_find_up(const double startwl, const double max){
double tmp = -42.0;
boost::thread up(&analyser::findup,*this, startwl,max,tmp);
std::cout << "before join " << tmp << std::endl;
up.join();
std::cout << "after join " << tmp << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
无论如何,我已经尝试过谷歌几乎任何东西,但我不能让它返回一个值.
输出现在看起来像这样.
before …Run Code Online (Sandbox Code Playgroud) 嗨,我有以下c ++程序:
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <boost/foreach.hpp>
#include <stdexcept>
#include <boost/flyweight.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
struct entry
{
int file;
std::vector<double> a;
};
void my_file(const std::string&file, std::vector<entry> &data, int i){
try{
std::ifstream in(file.c_str());
entry e;
std::string line;
e.file = i;
while(getline(in,line)){
try{
data[i].a.push_back( boost::lexical_cast<double> (line));
}catch(boost::bad_lexical_cast bad){
//std::cerr << bad.what() << std::endl;
}
}
}catch(std::runtime_error err){
std::cerr << err.what() << std::endl;
}
}
void write_file(const std::string &file,std::vector<entry> data,const char* t_path){
try{ …Run Code Online (Sandbox Code Playgroud) 我有这样的文件名: 09.04.201115_09_ch_4.txt
我想只提取filestem.我尝试使用boost文件系统路径,但它在文件名中有多个点有问题.(我没有提出命名).
有办法吗?我可以只获得没有扩展名的文件名吗?我的代码看起来像这样:
std::string stringtmp = path.parent_path().string() +"/"+path.stem().string()+".png" ;
Run Code Online (Sandbox Code Playgroud)
好的,这是代码(它使用ROOT框架):
#include "TH1F.h"
#include "TH2F.h"
#include "TF1.h"
#include "TSpectrum.h"
#include "TCanvas.h"
#include "TVirtualFitter.h"
#include "TMath.h"
#include "TGraph.h"
#include <fstream>
#include <iostream>
#include "TApplication.h"
#include "TImage.h"
#include <string>
#include <sstream>
#include "TStyle.h"
#include "TROOT.h"
#include "TGraph2D.h"
#include "boost/filesystem.hpp"
Int_t npeaks = 10;
Double_t fpeaks(Double_t *x, Double_t *par) {
Double_t result = par[0] + par[1]*x[0];
for (Int_t p=0;p<npeaks;p++) {
Double_t norm = par[3*p+2];
Double_t mean = par[3*p+3];
Double_t sigma = par[3*p+4];
result …Run Code Online (Sandbox Code Playgroud) 我正在尝试平均一个大的(~1.000.000数据集)向量.我已经有这样的数据:
struct data {
std::string alias;
double id;
std::string timestamp;
double value;
};
Run Code Online (Sandbox Code Playgroud)
现在我想平均一天的所有值.时间戳是这样的:"20-NOV-12 10.52.21.260000000 AM".我只关心substr(0,8),它包含描述当天的字符串部分.目前我有这个:
typedef std::vector<std::tuple<std::string, size_t, double>> days;
days&& average_days(const std::vector<data> _d)
{
days ret;
for(auto &d: _d) {
bool found = false;
int count = 0;
double val= 0.0;
for(size_t i = 0; i < ret.size(); i++) {
std::string day = d.alias.substr(0,8);
auto t = ret[i];
if (std::get<0>(t) == day) {
found = true;
std::string ali = std::get<0>(t);
size_t coun = std::get<1>(t) + 1;
double val …Run Code Online (Sandbox Code Playgroud)