我在使用shell脚本时遇到问题。 我尝试移动比参数传递的日期早的文件(作为#1传递给#1的文件夹中的#2),我目前使用
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
const int LENGTH = 10;
// declaration of functions sumArray() and printArray()
int sumArray(int [], int);
string printArray(string, string [], int [], int);
// declaration of main program
int main()
{
string blue_members[LENGTH], white_members[LENGTH];
int blue_scores[LENGTH], white_scores[LENGTH];
// 1) connect to the input file
ifstream fin("bowling.txt");
// declare arrays below
string Team, Member;
int Score;
// 2) initialize array accumulators to zero
int blue = 0;
int white = 0;
// 3) display a descriptive message
cout << "This program reads the lines from the file bowling.txt to determine\n"
<< "the winner of a bowling match. The winning team, members and scores\n"
<< "are displayed on the monitor.\n\n";
// 4) attempt to input the first line of the file
fin >> Member >> Team >> Score;
// 5) test ifstream.eof() condition
while (!fin.eof())
{
// 6) test team color is blue
if (Team == "Blue")
{
// 7) then store blue member and score
blue_scores[blue] = Score;
blue_members[blue] = Member;
// 8) increase blue array accumulator
blue++;
}
// 9) else store white member and score
else
{
white_scores[white] = Score;
white_members[white] = Member;
// 10) increase white array accumulator
white++;
}
// 11) attempt to input next line from file
fin >> Member >> Team >> Score;
}
// 12) if blue team score is larger
if (sumArray(blue_scores, blue) > sumArray(white_scores, white))
{
// 13 then display blue team as winner with the team
printArray(Team, blue_members, blue_scores, Score);
}
// 14) else display white team as winner with the team
else
{
printArray(Team, white_members, white_scores, Score);
}
}
// implement function sumArray() below
int sumArray(int array_name[], int array_end)
{
// 1. initialize accumulator to 0
int sum = 0;
// 2. loop over initialized array indices
for (int i = 0; i < array_end; i++)
// 3. increase accumulator by indexed array element
sum += array_name[i];
// 4. return accumulator
return sum;
}
// implement function printArray() below
void printArray(string team_name, string array_name [], int array_score [], int array_end)
{
// 1. display the team name as the winner
cout << setw(1) << "Winning Team: " << team_name<< endl;
cout << setw(5) << "Player" << setw(7) << "Score" << endl;
// 2. loop over initialized array indices
for (int i = 0; i < array_end; i++)
{
// 3. display member and score for that array index
cout << setw(3) << array_name[i]
<< setw(6) << setfill(' ') << array_score[i]
<< endl;
}
}
但问题是当日期在第10天之前。我不知道如何使这个数字大于订单,如01/07/16将小于13/06/16。有人能帮助我吗?
答案 0 :(得分:1)
您可能希望使用评论中建议的替代方法:
find -newerXY reference
将当前文件的时间戳与引用进行比较。该 reference参数通常是文件的名称(以及它的一个 timestamps用于比较)但它也可以是一个字符串 描述绝对时间。 X和Y是其他的占位符 字母,这些字母选择属于哪个时间 参考用于比较。
有些组合是 无效;例如,X无效为无效。一些组合 未在所有系统上实施;例如,不支持B. 所有系统。如果XY的组合无效或不受支持 指定,导致致命错误。解释时间规范 至于GNU日期的-d选项的参数。如果你试图使用 参考文件的出生时间,出生时间不能 确定后,会出现致命的错误消息。如果指定了哪个测试 是指正在检查的文件的出生时间,此测试将失败 对于出生时间未知的任何文件。
如果您想坚持使用脚本,只需更改ls
命令的格式即可。当您可能需要--time-style=+%d%m%y
时,您当前使用--time-style=+%y%m%d
(需要与脚本中的参数或切换相同的样式)。