C ++程序中的奇怪错误:删除打印分页程序 [英] Weird Error in C++ Program: Removing Printout Breaks Program
问题描述
这是一个很奇怪的问题...
删除cout在下面的功能导致它停止打印正确/预期的结果和打印垃圾值。 (即它仍然RUNS它输出的数据,但是,是错误的)。任何想法?
bool extract_tension(std :: vector< double>& interfacial_tension_trap,
std :: vector< double>& interfacial_tension_simp,
const std :: string data,
const unsigned int num_slabs,
const double z_min,const double z_max)
{
$ b b // start @ first number
unsigned int start = 17;
unsigned int end = 17;
std :: vector< double> px;
std :: vector< double> py;
std :: vector< double> pz;
std :: vector< double> pn_minus_pt;
double result_simp = 0.0;
double result_trap = 0.0;
//跳过时间条目
end = get_next_space(start,data);
for(unsigned int counter = 0; counter< num_slabs; counter ++)
{
start = end + 2;
end = get_next_space(start,data);
px.push_back(atof(data.substr(start,(end-start + 1))。c_str()));
//跳过空格
start = end + 2;
end = get_next_space(start,data);
py.push_back(atof(data.substr(start,(end-start + 1))。c_str()));
//跳过空格
start = end + 2;
end = get_next_space(start,data);
pz.push_back(atof(data.substr(start,(end-start + 1))。c_str()));
//计算压差
//警告:单位转换提前
// NAMD输出压力(单位为巴)和距离(单位为埃)
//我们需要一个积分结果mN / m。
// 1 Angstrom = 1e-10 m
// 1 bar = 1e8 mN / m ^ 2
//净转换 - 1e-2
pn_minus_pt.push_back pz [counter] -0.5 *(px [counter] + py [counter]))* 0.01);
std :: cout<< Current del_P:
<< (pz [counter] -0.5 *(px [counter] + py [counter]))* 0.01
< std :: endl;
}
calculate_trapezoid(pn_minus_pt,num_slabs,z_min,z_max,result_trap);
interfacial_tension_trap.push_back(result_trap);
calculate_simpson(pn_minus_pt,num_slabs,z_min,z_max,result_simp);
interfacial_tension_simp.push_back(result_simp);
}
显然,只要使用print语句触摸任何向量,程序就可以正确执行(即涉及px,py,OR pz的打印输出)
这是完整的程序:
/ *********************************
*
*姓名:界面张力计算器
*版本:0.1
*作者:Jason R. Mick
*集团:Wayne州立大学Pobff集团
*版权:(c)Jason R. Mick 2010
*日期:2010年8月9日
*
*更改日志
*版本日期评论
* ------------ -------------------------------------------------- --------
* 0.1 2010年8月9日完成的基本代码,无调试
* 0.5 2010年8月10日在Simpson的
*方法中编译和测试的代码固定错误结果被分割,而
*乘以。
*
*
*全额附注:
* --------------------------- -------------------------------------------
*你可以通过键入以下内容编译此程序:
* g ++ main.cc -o it_util
*
*您可以键入以下命令来运行此程序:
* it_util< filename> .log< #slabs> < z-min> < z-max>
*
*其中z-min和z-max表示系统的z轴边界,
* eg--
* it_util my_file.log 140 0.0 80.0
*
*此程序仅适用于NAMD * .log文件输出
*压力配置文件必须在* .conf文件中打开
*压力配置文件信息转储到* .log文件。这个
*程序需要该信息。
*
*这个程序可以处理1000多个slab,但是它对
*字符缓冲区有限制,因此非常大的slab计数可能会导致失败。
*
*使用标准的复合辛普森数值积分方法,
*假定非平滑数据集。
*
*界面张力在每个步骤被积分,然后平均
*,所以可以收集相关的统计数据。
*
*您可以重定向输出以存储界面张力
*统计如下:
* it_util< filename> .log<#slabs> < z-min> < z-max> > < my_file> .out
*
*********************************** ******** /
#include< stdio.h>
#include< math.h>
#include< iostream>
#include< vector>
#include< fstream>
#include< sys / stat.h>
//打开以启用所有界面
//拉伸结果打印,预平均化
//#define DEBUG true
start_integrations(const std :: string filename,
const unsigned int num_slabs,
const double z_min,const double z_max);
int main(int argc,char * argv [])
{
struct stat file_info;
std :: string filename = argv [1];
int slab_count;
double z_min;
double z_max;
if(argc!= 5)/ * argc应为3以正确执行* /
{
/ *打印正确的args语法* /
std: :cout< 错误:缺少参数! << std :: endl
< 正确的语法:< std :: endl
<< it_util< my_file> .log<#of slabs>< z-coord start>
<< < z-coord end>
<< std :: endl;
}
if(stat(argv [1],& file_info)== 0)
{
try
{
slab_count = atoi [2]);
if(slab_count> 2)
{
try
{
z_min = atof(argv [3]);
try
{
z_max = atof(argv [4]);
start_integrations(filename,
static_cast< unsigned int>(slab_count),
z_min,
z_max);
}
catch(char * str)
{
/ *无效的整数第三个输入* /
std :: cout< 输入无效 - 第四个参数无效
<< 十进制数,应该是标准< std :: endl
<< decimal type entry ...<< std :: endl
<< I.E. << std :: endl
<< it_util my_file.log 140 0.0 80.0< std :: endl;
}
}
catch(char * str)
{
/ *无效的整数第三个输入* /
std :: cout ;& 输入无效 - 第三个参数无效
<< 十进制数,应该是标准< std :: endl
<< decimal type entry ...<< std :: endl
<< I.E. << std :: endl
<< it_util my_file.log 140 0.0 80.0< std :: endl;
}
}
else
{
/ *无效的整数二次输入* /
std :: cout< 无效的输入 - 第二个参数是无效的整数,
<< 应该是无符号整数2或更大...< std :: endl
<< I.E. << std :: endl
<< it_util my_file.log 140 0.0 80.0< std :: endl;
}
}
catch(char * str)
{
/ *非整数辅助输入* /
std :: cout< 无效的输入 - 第二个参数是非整数,
<< 应该是无符号整数2或更大...< std :: endl
<< I.E. << std :: endl
<< it_util my_file.log 140 0.0 80.0< std :: endl;
}
}
else
{
/ *无效的文件名case ... * /
std :: cout< File<< filename<< 不存在! << std :: endl
<< 请选择有效的文件! << std :: endl;
}
return 1;
}
bool calculate_simpson(const std :: vector< double> my_values,
const unsigned int num_points,
const double x_min,const double x_max,
double& results)
{
bool ret_val = false;
bool is_even = true;
double h;
if(my_values.size()> = 2)
{
h =(x_max-x_min)/ num_points;
results + = my_values.front();
for(unsigned int counter = 1; counter< num_points-1; counter ++)
{
if(is_even)
{
results + = 4 * my_values [ ;
}
else
{
results + = 2 * my_values [counter];
}
is_even =!is_even;
}
results + = my_values.back();
results * =(h / 3);
ret_val = true;
}
return ret_val;
}
bool calculate_trapezoid(const std :: vector< double> my_values,
const unsigned int num_points,
const double x_min,const double x_max,
double& results)
{
bool ret_val = false;
double x_incr =(x_max-x_min)/(num_points-1)
if(my_values.size()> = 2)
{
for(unsigned int counter = 1; counter {
results + =(x_incr / 2)*(my_values [counter] + my_values [counter-1]);
}
}
return ret_val;
}
unsigned int get_next_space(const unsigned int start,
const std :: string data)
{
unsigned int counter = start;
while(data.length()> counter&&
data.substr(counter,1).compare()!= 0)
{
counter ++;
}
//如果字符串结束,添加一个
if(data.length()== counter)
counter ++;
return(counter-1);
}
bool extract_tension(std :: vector< double>& interfacial_tension_trap,
std :: vector< double>& interfacial_ension_simp,
const std ::字符串数据
const unsigned int num_slabs,
const double z_min,const double z_max)
{
//开始@第一个数字
unsigned int start = 17;
unsigned int end = 17;
std :: vector< double> px;
std :: vector< double> py;
std :: vector< double> pz;
std :: vector< double> pn_minus_pt;
double result_simp = 0.0;
double result_trap = 0.0;
//跳过时间条目
end = get_next_space(start,data);
for(unsigned int counter = 0; counter< num_slabs; counter ++)
{
start = end + 2;
end = get_next_space(start,data);
px.push_back(atof(data.substr(start,(end-start + 1)).c_str()));
//跳过空格
start = end + 2;
end = get_next_space(start,data);
py.push_back(atof(data.substr(start,(end-start + 1))。c_str()));
//跳过空格
start = end + 2;
end = get_next_space(start,data);
pz.push_back(atof(data.substr(start,(end-start + 1))。c_str()));
//计算压力差
//警告:单位转换提前
// NAMD输出压力(单位为巴)和距离(单位为埃)
//我们需要一个积分结果mN / m。
// 1 Angstrom = 1e-10 m
// 1 bar = 1e8 mN / m ^ 2
//净转换 - 1e-2
pn_minus_pt.push_back pz [counter] -0.5 *(px [counter] + py [counter]))* 0.01);
std :: cout<< Current del_P:
<< (pz [counter] -0.5 *(px [counter] + py [counter]))* 0.01
< std :: endl;
}
calculated_trapezoid(pn_minus_pt,num_slabs,z_min,z_max,result_trap);
interfacial_tension_trap.push_back(result_trap);
calculate_simpson(pn_minus_pt,num_slabs,z_min,z_max,result_simp);
interfacial_tension_simp.push_back(result_simp);
}
double average_vector(std :: vector< double> my_vector)
{
double average_val = 0.0;
for(unsigned int counter = 0; counter< my_vector.size(); counter ++)
{
average_val + = my_vector [counter] /my_vector.size
}
return average_val;
}
double std_dev_vector(std :: vector< double> my_vector)
{
double std_deviation = 0.0;
double average_val = average_vector(my_vector);
for(unsigned int counter = 0; counter< my_vector.size(); counter ++)
{
std_deviation + =(my_vector [counter] -average_val)*
(my_vector [counter] -average_val);
}
std_deviation = sqrt(std_deviation);
return std_deviation;
}
void start_integrations(const std :: string filename,
const unsigned int num_slabs,
const double z_min,const double z_max)
{
std :: ifstream in_file;
std :: vector< double> interfacial_tension_trap;
std :: vector< double>界面张力
std :: string current_line;
char * cstr_line;
bool data_grab_success = true;
in_file.open(filename.c_str(),std :: ifstream :: in);
while(!in_file.eof()&& data_grab_success)
{
cstr_line =(char *)malloc(sizeof(char)* 65536);
//获取新行
in_file.getline(cstr_line,65536);
current_line = cstr_line;
free(cstr_line);
if(current_line.substr(0,15).compare(PRESSUREPROFILE)== 0)
{
//压力剖面找到!
//处理行以获得界面张力,检查它是否成功
data_grab_success = extract_tension(interfacial_tension_trap,
interfacial_tension_simp,
current_line,
num_slabs,
z_min,
z_max);
}
}
in_file.close();
//打印统计信息
std :: cout<< 界面张力(梯形法):
< average_vector(interfacial_tension_trap)<< std :: endl
<< Standard Deviation(Trapezoid Method):
<< std_dev_vector(interfacial_tension_trap)<< std :: endl
<< 界面张力(Composite Simpson's Method):
< average_vector(interfacial_ension_simp)<< std :: endl
<< Standard Deviation(Composite Simpson's Method):
<< std_dev_vector(interfacial_tension_simp)<< std :: endl;
}
下面是一组数据示例:
已移除...请参阅说明文章末尾的链接到要使用的数据。
编译如下:
g ++ main.cc -o it_util
使用命令运行:
it_util equil2_NVT_PP_318Slabs.log 318 0.0 318.0>请注意,在有人对我的#ifdefdebug语句发表评论之前,我应该注意到,它们都是are,因为它们都是/用于数据转储。我以前使用过GDB。我猜我没有说这个,有人会评论学习使用gdb。在这种情况下,程序循环通过这么多的迭代,GDB不给我有用的信息,其中打印输出到输出文件DO。
注意:
实际上,我发现如果你使用被分析的文件的截断版本(在上面的数据部分),程序也不会输出正确的数据。当我恢复原始的数据文件,它工作,但文件太大,不能发布在这里(我试过...)所以这不是一个选项....
相反,我上传了一个完整的pastebin到这里:
http://pastebin.com/JasbSc7B
解决方案这很奇怪...
所以我想出了问题。这是一个很业余的错误。我忘了在data_grab_success上返回布尔成功。
然而,这不解释奇怪的部分 - 不知何故这个值被自动填充为false - 除非我跑那哥哥。无论如何我很高兴问题解决了,因为我疯了,但我很困惑,如果一个函数获取它的返回值如果没有指定和cout如何影响... ...
(
$ b 感谢Dugan给予的忠告! p>
This is a very strange problem...
removing the cout in the function below causes it to stop printing the correct/expected results and printing garbage values. (i.e. it still RUNS the data it outputs, though, is wrong). Any ideas?
bool extract_tension(std::vector<double> &interfacial_tension_trap,
std::vector<double> &interfacial_tension_simp,
const std::string data,
const unsigned int num_slabs,
const double z_min, const double z_max)
{
//start @ first number
unsigned int start = 17;
unsigned int end = 17;
std::vector<double> px;
std::vector<double> py;
std::vector<double> pz;
std::vector<double> pn_minus_pt;
double result_simp=0.0;
double result_trap=0.0;
//skip timestep entry
end=get_next_space(start, data);
for(unsigned int counter=0; counter<num_slabs;counter++)
{
start = end+2;
end=get_next_space(start, data);
px.push_back(atof(data.substr(start,(end-start+1)).c_str()));
//skip the space
start = end+2;
end=get_next_space(start, data);
py.push_back(atof(data.substr(start,(end-start+1)).c_str()));
//skip the space
start = end+2;
end=get_next_space(start, data);
pz.push_back(atof(data.substr(start,(end-start+1)).c_str()));
//calculate pressure difference
// WARNING : Unit conversion ahead
// NAMD outputs pressure in bars and distance in Angstroms
// we want an integrated result of mN/m, instead.
// 1 Angstrom = 1e-10 m
// 1 bar = 1e8 mN/m^2
// net conversion -- 1e-2
pn_minus_pt.push_back((pz[counter]-0.5*(px[counter]+py[counter]))*0.01);
std::cout << "Current del_P : "
<< (pz[counter]-0.5*(px[counter]+py[counter]))*0.01
<< std::endl;
}
calculate_trapezoid(pn_minus_pt, num_slabs, z_min, z_max, result_trap);
interfacial_tension_trap.push_back(result_trap);
calculate_simpson(pn_minus_pt, num_slabs, z_min, z_max, result_simp);
interfacial_tension_simp.push_back(result_simp);
}
Apparently just touching any of vectors with a print statement allows the program to execute correctly (i.e. a printout involving px, py, OR pz)
Here's the full program:
/*********************************
*
* NAME: Interfacial Tension Calculator
* VERSION: 0.1
* AUTHOR: Jason R. Mick
* GROUP: Wayne State University, Potoff Group
* COPYRIGHT: (c) Jason R. Mick 2010
* DATE: August 9, 2010
*
* CHANGE LOG
* VERSION DATE COMMENTS
*----------------------------------------------------------------------
* 0.1 Aug. 9, 2010 Finished basic code, sans debugging
* 0.5 Aug 10, 2010 Compiled and tested code fixed error in Simpson's
* method where results were being divided rather
* than multiplied.
*
*
* FULL NOTES:
*----------------------------------------------------------------------
* You can compile this program by typing:
* g++ main.cc -o it_util
*
* You can run this program by typing:
* it_util <filename>.log <# slabs> <z-min> <z-max>
*
* where z-min and z-max represent the z-axis boundaries of the system,
* e.g.--
* it_util my_file.log 140 0.0 80.0
*
* This program only works with NAMD *.log file output
* The pressure profile MUST be turned on in your *.conf file
* for the pressure profile info to dump to the *.log file. This
* program requires that info.
*
* This program can handle 1,000+ slabs, but it has a limit to the
* character buffer and thus VERY large slab counts may cause it to fail.
*
* A standard Composite Simpson numerical integration method is used,
* which assumes a non-smooth data set.
*
* The interfacial tension is integrated at each step and then averaged
* so pertinent statistics can be gathered.
*
* You can redirect the output to store the interfacial tension
* statistics as follows:
* it_util <filename>.log <# slabs> <z-min> <z-max> > <my_file>.out
*
*******************************************/
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <fstream>
#include <sys/stat.h>
//Turn on to enable all interfacial
//tension results to be printed, pre-averaging
//#define DEBUG true
void start_integrations(const std::string filename,
const unsigned int num_slabs,
const double z_min, const double z_max);
int main ( int argc, char *argv[] )
{
struct stat file_info;
std::string filename = argv[1];
int slab_count;
double z_min;
double z_max;
if ( argc != 5 ) /* argc should be 3 for correct execution */
{
/*Print out proper args syntax */
std::cout << "ERROR: Missing arguments!" << std::endl
<< "Proper syntax:" << std::endl
<< "it_util <my_file>.log <# of slabs> <z-coord start>"
<< "<z-coord end>"
<< std::endl;
}
if(stat(argv[1],&file_info)==0)
{
try
{
slab_count = atoi(argv[2]);
if (slab_count > 2)
{
try
{
z_min = atof(argv[3]);
try
{
z_max = atof(argv[4]);
start_integrations(filename,
static_cast<unsigned int>(slab_count),
z_min,
z_max);
}
catch( char * str )
{
/*invalid integer third input*/
std::cout << "Invalid input -- fourth argument was invalid "
<< "decimal number, should be standard " << std::endl
<< "decimal type entry..." << std::endl
<< "I.E." << std::endl
<< "it_util my_file.log 140 0.0 80.0" << std::endl;
}
}
catch( char * str )
{
/*invalid integer third input*/
std::cout << "Invalid input -- third argument was invalid "
<< "decimal number, should be standard " << std::endl
<< "decimal type entry..." << std::endl
<< "I.E." << std::endl
<< "it_util my_file.log 140 0.0 80.0" << std::endl;
}
}
else
{
/*invalid integer secondary input*/
std::cout << "Invalid input -- second argument was invalid integer, "
<< "should be unsigned integer 2 or greater..." << std::endl
<< "I.E." << std::endl
<< "it_util my_file.log 140 0.0 80.0" << std::endl;
}
}
catch( char * str )
{
/*non integer secondary input*/
std::cout << "Invalid input -- second argument was non-integer, "
<< "should be unsigned integer 2 or greater..." << std::endl
<< "I.E." << std::endl
<< "it_util my_file.log 140 0.0 80.0" << std::endl;
}
}
else
{
/*invalid filename case...*/
std::cout << "File " << filename << "does not exist!" << std::endl
<< "Please choose valid file!" << std::endl;
}
return 1;
}
bool calculate_simpson(const std::vector<double> my_values,
const unsigned int num_points,
const double x_min, const double x_max,
double &results)
{
bool ret_val = false;
bool is_even = true;
double h;
if (my_values.size() >= 2)
{
h = (x_max-x_min)/num_points;
results+=my_values.front();
for (unsigned int counter=1; counter<num_points-1;counter++)
{
if (is_even)
{
results+=4*my_values[counter];
}
else
{
results+=2*my_values[counter];
}
is_even = !is_even;
}
results+=my_values.back();
results*=(h/3);
ret_val=true;
}
return ret_val;
}
bool calculate_trapezoid(const std::vector<double> my_values,
const unsigned int num_points,
const double x_min, const double x_max,
double &results)
{
bool ret_val = false;
double x_incr = (x_max-x_min)/(num_points-1);
if (my_values.size() >= 2)
{
for (unsigned int counter=1; counter<num_points-1; counter++)
{
results+=(x_incr/2)*(my_values[counter]+my_values[counter-1]);
}
}
return ret_val;
}
unsigned int get_next_space(const unsigned int start,
const std::string data)
{
unsigned int counter=start;
while (data.length() > counter &&
data.substr(counter,1).compare(" ") != 0)
{
counter++;
}
//if end of string, add one
if ( data.length() == counter)
counter++;
return (counter-1);
}
bool extract_tension(std::vector<double> &interfacial_tension_trap,
std::vector<double> &interfacial_tension_simp,
const std::string data,
const unsigned int num_slabs,
const double z_min, const double z_max)
{
//start @ first number
unsigned int start = 17;
unsigned int end = 17;
std::vector<double> px;
std::vector<double> py;
std::vector<double> pz;
std::vector<double> pn_minus_pt;
double result_simp=0.0;
double result_trap=0.0;
//skip timestep entry
end=get_next_space(start, data);
for(unsigned int counter=0; counter<num_slabs;counter++)
{
start = end+2;
end=get_next_space(start, data);
px.push_back(atof(data.substr(start,(end-start+1)).c_str()));
//skip the space
start = end+2;
end=get_next_space(start, data);
py.push_back(atof(data.substr(start,(end-start+1)).c_str()));
//skip the space
start = end+2;
end=get_next_space(start, data);
pz.push_back(atof(data.substr(start,(end-start+1)).c_str()));
//calculate pressure difference
// WARNING : Unit conversion ahead
// NAMD outputs pressure in bars and distance in Angstroms
// we want an integrated result of mN/m, instead.
// 1 Angstrom = 1e-10 m
// 1 bar = 1e8 mN/m^2
// net conversion -- 1e-2
pn_minus_pt.push_back((pz[counter]-0.5*(px[counter]+py[counter]))*0.01);
std::cout << "Current del_P : "
<< (pz[counter]-0.5*(px[counter]+py[counter]))*0.01
<< std::endl;
}
calculate_trapezoid(pn_minus_pt, num_slabs, z_min, z_max, result_trap);
interfacial_tension_trap.push_back(result_trap);
calculate_simpson(pn_minus_pt, num_slabs, z_min, z_max, result_simp);
interfacial_tension_simp.push_back(result_simp);
}
double average_vector(std::vector<double> my_vector)
{
double average_val=0.0;
for(unsigned int counter=0; counter< my_vector.size(); counter++)
{
average_val+=my_vector[counter]/my_vector.size();
}
return average_val;
}
double std_dev_vector(std::vector<double> my_vector)
{
double std_deviation=0.0;
double average_val = average_vector(my_vector);
for(unsigned int counter=0; counter< my_vector.size(); counter++)
{
std_deviation+=(my_vector[counter]-average_val)*
(my_vector[counter]-average_val);
}
std_deviation=sqrt(std_deviation);
return std_deviation;
}
void start_integrations(const std::string filename,
const unsigned int num_slabs,
const double z_min, const double z_max)
{
std::ifstream in_file;
std::vector<double> interfacial_tension_trap;
std::vector<double> interfacial_tension_simp;
std::string current_line;
char * cstr_line;
bool data_grab_success = true;
in_file.open(filename.c_str(), std::ifstream::in);
while (!in_file.eof() && data_grab_success)
{
cstr_line=(char *) malloc(sizeof(char)*65536);
//get new line
in_file.getline(cstr_line,65536);
current_line = cstr_line;
free(cstr_line);
if (current_line.substr(0,15).compare("PRESSUREPROFILE")==0)
{
//pressure profile found!
//process line to get the interfacial tension, check that it succeeded
data_grab_success = extract_tension(interfacial_tension_trap,
interfacial_tension_simp,
current_line,
num_slabs,
z_min,
z_max);
}
}
in_file.close();
//print stats
std::cout << "Interfacial Tension (Trapezoid Method): "
<< average_vector(interfacial_tension_trap) << std::endl
<< "Standard Deviation (Trapezoid Method): "
<< std_dev_vector(interfacial_tension_trap) << std::endl
<< "Interfacial Tension (Composite Simpson's Method): "
<< average_vector(interfacial_tension_simp) << std::endl
<< "Standard Deviation (Composite Simpson's Method): "
<< std_dev_vector(interfacial_tension_simp) << std::endl;
}
And here's a sample set of data:
Removed... see explanation at end of post for link to data to use.
Compile like so:
g++ main.cc -o it_util
Run using the command:
it_util equil2_NVT_PP_318Slabs.log 318 0.0 318.0 > temp.out
FYI before someone comments on my #ifdef "debug" statements, please note that they are for data dumping. I have used GDB before. I'm guessing had I not said this, someone will comment "Learn to use gdb." In this case the program loops through so many iterations, GDB doesn't give me useful info, where printouts dumped to a output file DO.
NOTE:
Actually I discovered that if you use the chopped down version of the file being parsed (in the data section above) the program also doesn't output the correct data. When I restored the original data file it worked, but the file is too large to post here (I tried...) so that is not an option....
Instead I've uploaded a full pastebin to here:
http://pastebin.com/JasbSc7B
解决方案 This is strange...
So I figured out the problem. It was a pretty amateurish mistake. I forgot to return the boolean success on data_grab_success.
However that doesn't explain the strange part -- somehow this value was getting filled with false automatically -- unless I ran that cout. Anyways I'm happy the problem is solved because I was going crazy, but I'm perplexed as to where it a function gets its return value if none is specified and how cout could influence that...
(P.S. I finally figured this out by using GDB after all....)
Thanks to Dugan for giving solid advice!
这篇关于C ++程序中的奇怪错误:删除打印分页程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!