gpt4 book ai didi

c++ - 使用存档输入的 C++ 程序有什么问题?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:54:17 24 4
gpt4 key购买 nike

<分区>

我有以下 C++ 代码:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
int N;
string s;
char str[100];
scanf("%d",&N);

for(int i=0; i<N; i++)
{
fflush(stdin);
fgets(str,100,stdin);
s = str;
cout << s << endl;
}

return 0;
}

代码保存在存档 test.cpp 中。

在Linux Ubuntu上使用终端编译:

g++ -c hello.cpp
g++ -o hello hello.o

我有一个存档 test.in 将作为输入:

5
God of War
Grand Theft Auto
The Smurfs
Final Fantasy
Call of Duty

在终端中运行命令:

./test < test.in

输出将是:

rogerio@rogerio-Aspire-5741Z:~/Documentos$ ./teste < teste.in


God of War

Grand Theft Auto

The Smurfs

Final Fantasy

rogerio@rogerio-Aspire-5741Z:~/Documentos$

因为“使命召唤”这一行被跳过了?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com