我正在使用Round Robin调度程序模拟器,所以我有4个文件A.txt,B.txt,C.txt,D.txt。每个代表一个过程,其中的每一行代表一条指令。每行都有o,p,q,r行。所以我想从这些文件中创建一个文件RR.txt。即。量子= 8。
8 lines of file A
8 lines of file B
8 lines of file C
8 lines of file D
next 8 lines of file A
next 8 lines of file B
next 8 lines of file C
next 8 lines of file D
...
and so on until run out of lines on all files.
我已经在阵列上找到了文件名
string names_processes[number_of_processes];
并从我创建的每个函数中获取行数
int countLines(const string& inputFile){
int counter=0;ifstream file(inputFile);string str;
while (getline(file, str)) {counter++;}
return counter;
}
并像使用它
int o = countLines(names_processes[0]); //file A.txt
int p = countLines(names_processes[1]); //file B.txt
int q = countLines(names_processes[2]); //file C.txt
int r = countLines(names_processes[3]); //file D.txt
答案 0 :(得分:0)
假设您需要从文件中获得8行,则可以执行以下操作:
def collide():
arrow_pos = (arrow.x + arrow.w // 2, arrow.y + arrow.h // 2)
mpos = (-1, -1)
if arrow.alive:
for event in pygame.event.get():
print(event)
if event.type == pygame.MOUSEBUTTONUP:
mpos = pygame.mouse.get_pos()
print(mpos)
for square in squares:
if square.rect.collidepoint(mpos):
square.act = not square.act
if square.act:
if arrow_pos == square.center:
square.run()
如果达到eof或读取8行,此处std::vector<string> getLines(const string& inputFile){
int counter;
std::vector<string> lines;
ifstream file(inputFile);
std::string str;
for(counter = 0; getline(file, str) && counter < 8; counter++){
lines.push_back(str);
}
return lines;
}
将退出循环。