我没有使用 C++ 的经验,并且获得了一个应该能够在没有任何调试的情况下运行的代码,但是,当我尝试编译它时出现了一堆错误。我只需要一些关于如何开始调试它的指导,我们将不胜感激。这是错误消息:
mpicc -c -O3 curvilinear_grid.cpp
In file included from parameters.h:12:0,
from curvilinear_grid.h:13,
from curvilinear_grid.cpp:6:
parameter_file_parser.h: In member function ‘int PARAMETER_FILE_PARSER<T>::Parse_Parameter_File()’:
parameter_file_parser.h:86:13: error: invalid use of incomplete type ‘std::ifstream {aka struct std::basic_ifstream<char>}’
/usr/include/c++/4.6/iosfwd:113:11: error: declaration of ‘std::ifstream {aka struct std::basic_ifstream<char>}’
parameter_file_parser.h:92:29: error: no matching function for call to ‘getline(std::ifstream&, std::string&)’
parameter_file_parser.h:92:29: note: candidates are:
/usr/include/c++/4.6/bits/basic_string.tcc:1070:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
/usr/include/c++/4.6/bits/basic_string.h:2734:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)
parameter_file_parser.h:95:21: error: no match for ‘operator>>’ in ‘tokens >> std::ws’
parameter_file_parser.h:95:21: note: candidates are:
/usr/include/c++/4.6/bits/basic_string.tcc:998:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/istream.tcc:957:5: note: template<class _CharT2, class _Traits2> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT2*)
/usr/include/c++/4.6/bits/istream.tcc:925:5: note: template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT&)
/usr/include/c++/4.6/istream:709:5: note: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char&)
/usr/include/c++/4.6/istream:714:5: note: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&)
/usr/include/c++/4.6/istream:756:5: note: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char*)
/usr/include/c++/4.6/istream:761:5: note: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char*)
parameter_file_parser.h:95:51: error: no matching function for call to ‘getline(std::istringstream&, std::string&, char)’
parameter_file_parser.h:95:51: note: candidates are:
/usr/include/c++/4.6/bits/basic_string.tcc:1070:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
/usr/include/c++/4.6/bits/basic_string.h:2734:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)
parameter_file_parser.h:96:14: error: no match for ‘operator>>’ in ‘tokens >> std::ws’
parameter_file_parser.h:96:14: note: candidates are:
/usr/include/c++/4.6/bits/basic_string.tcc:998:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.6/bits/istream.tcc:957:5: note: template<class _CharT2, class _Traits2> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT2*)
/usr/include/c++/4.6/bits/istream.tcc:925:5: note: template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT&)
/usr/include/c++/4.6/istream:709:5: note: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char&)
/usr/include/c++/4.6/istream:714:5: note: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&)
/usr/include/c++/4.6/istream:756:5: note: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char*)
/usr/include/c++/4.6/istream:761:5: note: template<class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char*)
parameter_file_parser.h:96:41: error: no matching function for call to ‘getline(std::istringstream&, std::string&)’
parameter_file_parser.h:96:41: note: candidates are:
/usr/include/c++/4.6/bits/basic_string.tcc:1070:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
/usr/include/c++/4.6/bits/basic_string.h:2734:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)
parameter_file_parser.h:107:8: error: invalid use of incomplete type ‘std::ifstream {aka struct std::basic_ifstream<char>}’
/usr/include/c++/4.6/iosfwd:113:11: error: declaration of ‘std::ifstream {aka struct std::basic_ifstream<char>}’
make: *** [curvilinear_grid.o] Error 1
错误信息相关代码:
// File: parameter_file_parser.h
// Desc: Parser of the parameter input file to change default parameter values
#ifndef __PARAMETER_FILE_PARSER__
#define __PARAMETER_FILE_PARSER__
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
template<class T=double>
class PARAMETER_FILE_PARSER
{
public:
PARAMETER_FILE_PARSER(string filename) : parameter_filename(filename)
{param_map=NULL;}
~PARAMETER_FILE_PARSER() {if(param_map) delete param_map;}
int Parse_Parameter_File();
bool Get_Value(string key, int& value)
{
if(!param_map) return false;
map<string,string>::iterator i = (*param_map).find(key);
if(i != (*param_map).end()){
value = atoi(i->second.c_str());
return true;
}else return false;
}
bool Get_Value(string key, double& value)
{
if(!param_map) return false;
map<string,string>::iterator i = (*param_map).find(key);
if(i!=(*param_map).end()){
value = atof(i->second.c_str());
return true;
}else return false;
}
bool Get_Value(string key, string& value)
{
if(!param_map) return false;
map<string,string>::iterator i = (*param_map).find(key);
if(i!=(*param_map).end()){
string raw_val = i->second;
size_t ip1,ip2;
ip1 = raw_val.find('"');
ip2 = raw_val.find('"',ip1+1);
if(ip1!=string::npos && ip2!=string::npos){
value = raw_val.substr(ip1+1,ip2-ip1-1);
return true;
}else return false;
}else return false;
}
/*
bool Get_Value(string key, bool& value)
{
if(!param_map) return false;
map<string,string>::iterator i = (*param_map).find(key);
if(i!=(*param_map).end()){
switch(i->second){ //make lowercase
case "true": value = true;break;
case "false": value = false;break;
}
return true;
}else return false;
}else return false;
}
*/
bool Processed() {return param_map!=NULL;}
private:
map<string, string> *param_map;
string parameter_filename;
};
//*****************************************************************************
// Parsing parameter_filename and populating the parameters map
//*****************************************************************************
template<class T>
int PARAMETER_FILE_PARSER<T>::Parse_Parameter_File()
{
ifstream pfile(parameter_filename.c_str());
if (!pfile.is_open())
{cout << "Unable to open parameter file:parameter_filename"<<endl;return 0;}
param_map = new map<string, string>();
string line,key, value;
while (getline(pfile, line))
{
istringstream tokens(line);
while(tokens >> ws && getline(tokens, key, '=') &&
tokens >> ws && getline(tokens, value)){
key.erase(remove(key.begin(),key.end(),' '),key.end());
size_t i = value.find("//");
if(i!=string::npos) {
value = value.substr(0,i-1);
value.erase(remove(value.begin(),value.end(),' '),value.end());
}
(*param_map)[key] = value;
}
}
pfile.close();
return 1;
}
//*****************************************************************************
#endif
最佳答案
如果您阅读第一条错误消息:
invalid use of incomplete type ‘std::ifstream’
你会看到类型 std::ifstream没有被定义。它在 header 中定义 <fstream> , 所以你需要包括它。
代码还使用了std::istringstream ,这需要 <sstream> .
大多数其他错误应该被修复。
此外,虽然它不会导致错误,但您应该避免使用保留名称,例如 __PARAMETER_FILE_PARSER__ .通常,不要使用前导或双下划线。
关于c++ - 如何在 C++ 中解释以下错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16049291/
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
这可能是个愚蠢的问题。但是,我是一个新手......你怎么能在交互式rubyshell中有多行代码?好像你只能有一条长线。按回车键运行代码。无论如何我可以在不运行代码的情况下跳到下一行吗?再次抱歉,如果这是一个愚蠢的问题。谢谢。 最佳答案 这是一个例子:2.1.2:053>a=1=>12.1.2:054>b=2=>22.1.2:055>a+b=>32.1.2:056>ifa>b#Thecode‘if..."startsthedefinitionoftheconditionalstatement.2.1.2:057?>puts"f