我使用boost :: split来解析数据文件.数据文件包含如下行.
data.txt中
1:1~15 ASTKGPSVFPLAPSS SVFPLAPSS -12.6 98.3
Run Code Online (Sandbox Code Playgroud)
项目之间的空白区域是标签.我必须拆分上述代码的代码如下.
std::string buf;
/*Assign the line from the file to buf*/
std::vector<std::string> dataLine;
boost::split( dataLine, buf , boost::is_any_of("\t "), boost::token_compress_on); //Split data line
cout << dataLine.size() << endl;
Run Code Online (Sandbox Code Playgroud)
对于上面的代码行,我应该得到5的打印,但我得到6.我试图阅读文档,这个解决方案似乎应该做我想要的,显然我错过了一些东西.谢谢!
编辑:在dataLine上运行forloop,如下所示:
cout << "****" << endl;
for(int i = 0 ; i < dataLine.size() ; i ++) cout << dataLine[i] << endl;
cout << "****" << endl;
****
1:1~15
ASTKGPSVFPLAPSS
SVFPLAPSS
-12.6
98.3
****
Run Code Online (Sandbox Code Playgroud) 我正在编写一个脚本来从文件中读取命令并执行特定命令.我希望我的脚本适用于单个输入参数,或者当参数是包含有问题参数的文件名时.
我的代码除了一个问题外,它的代码无效,它忽略了文件的最后一行.所以,如果文件如下.
file.txt的
file1
file2
Run Code Online (Sandbox Code Playgroud)
下面发布的脚本仅运行file.txt的命令
for currentJob in "$@"
do
if [[ "$currentJob" != *.* ]] #single file input arg
then
echo $currentJob
serverJobName="$( tr '[A-Z]' '[a-z]' <<< "$currentJob" )" #Change to lowercase
#run cURL job
curl -o "$currentJob"PisaInterfaces.xml http://www.ebi.ac.uk/msd-srv/pisa/cgi-bin/interfaces.pisa?"$serverJobName"
else #file with list of pdbs
echo "Reading "$currentJob
while read line; do
echo "-"$line
serverJobName="$( tr '[A-Z]' '[a-z]' <<< "$line" )"
curl -o "$line"PisaInterfaces.xml http://www.ebi.ac.uk/msd-srv/pisa/cgi-bin/interfaces.pisa?"$serverJobName"
done < "$currentJob"
fi
done
Run Code Online (Sandbox Code Playgroud)
当然,有一个显而易见的工作,在while循环后我重复循环内部的步骤以完成最后一个文件的命令,但这是不可取的,因为我在while循环中所做的任何更改都必须重复在while循环之外.我在网上搜索过,找不到有人问这个确切的问题.我确信它在那里,但我还没有找到它.
我得到的输出如下.
>testScript.sh file.txt
Reading file.txt
-file1
% …Run Code Online (Sandbox Code Playgroud) 一段时间以来,我一直在努力解决这个设计问题.我将尽我所能来解释我正在尝试做什么以及我所看到的各种接近,我正在尝试什么以及为什么.
我在科学计算环境中工作,在那里我反复处理相同类型的对象.想象一个包含太阳系的星系,每个太阳系都包含行星系统,每个行星系统都包含卫星.为此,我将这种情况视为一种"有"的情况,因此我使用组合来让银河系进入其太阳系,并且每个太阳系都可以进入可以进入卫星的行星系统:每个类别是自己的阶级.
通常情况下,我正在处理的各种问题包含有关这些对象的不同类型的数据.而且,随着不同类型的数据变得可用,我可以使用我的对象做某些事情.所以,当我有数据类型1可供我使用时,我创建以下类
class GalaxyOne { /* … */ };
class SolarSystemOne { /* … */ };
class PlanetOne{ /* … */ };
class MoonOne{ /* … */ };
Run Code Online (Sandbox Code Playgroud)
当我有数据类型2可供我使用时,我创建
class GalaxyTwo { /* … */ };
class SolarSystemTwo { /* … */ };
class PlanetTwo{ /* … */ };
class MoonTwo{ /* … */ };
Run Code Online (Sandbox Code Playgroud)
每个类的复合方面通过使用容器变量来处理,例如包含指向所包含类的指针的向量.例如,在每个Galaxy类中都可以找到.
class GalaxyTwo{ /* … */
protected:
std::vector<SolarSystemTwo*> solarSystems;
/* … */
};
Run Code Online (Sandbox Code Playgroud)
当我想将类组合成高阶类时,困难就出现了.
class GalaxyOneTwo: public GalaxyOne, public GalaxyTwo{
/* Additional methods */ …Run Code Online (Sandbox Code Playgroud) 我四处寻找解决这个问题的办法,却无法发现任何问题.我相信这是一个快速解决方案,希望有人可以发现我的错误并告诉我.
这就是我所拥有的
#include<algorithm>
#include<vector>
void myFunction ( cont std::vector<std::vector<int> > &counts){
std::vector<int>::iterator max_it;
int index;
for ( int i = 0 ; i < counts.size() ; i ++ ){
max_it = std::max_element(counts[i].begin(), counts[i].end());
index = std::distance(counts[i].begin(),max_it);
}
}
Run Code Online (Sandbox Code Playgroud)
在编译上面的代码时,我得到了调用max_element的行的以下错误.
error: no match for ‘operator=’ in ‘it = std::max_element [with _ForwardIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >](((const std::vector<int, std::allocator<int> >*)((const std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >*)counts)->std::vector<_Tp, _Alloc>::operator[] [with _Tp = std::vector<int, std::allocator<int> >, _Alloc = std::allocator<std::vector<int, std::allocator<int> > …Run Code Online (Sandbox Code Playgroud)