使用g++的c++输出中的额外细节
Extra details in output of c++ using g++
我用c++编写了一个程序,没有编译错误,运行良好,但在输出结束时,它总是在同一行显示我的设备名称和目录。我试过使用endl,但仍然没有改变(我正在使用g++)程序代码如下
#include<iostream>
using namespace std;
int max(int *,int);
int main()
{int n,a[10],b;
cout<<"Please enter the no. of integers you wish to enter ";
cin>>n;
for(int i=0;i<n;i++)
{cout<<endl<<"please enter the "<<i+1<<" no. ";
cin>>a[i];
}
b=max(a,n);
cout<<endl<<"The greatest no. is "<<a[b]<<" and its index position is "<<b<<endl;
return 0;
}
int max(int *ptr,int n)
{int i,max,k=0;
max=ptr[0];
for(i=0;i<n;i++)
{if(max<ptr[i])
{max=ptr[i];
k=i;
}
}
return k;
}
和输出请输入号码。希望输入4的整数
请输入1号。2
请输入2号。4
请输入3号。6
请输入4号。1
最大的no。为6,索引位置为2*himanshu@hunt:~/Documents/Himanshu/c++ $*
从您给出的所有信息来看,似乎没有在输出结束时打印新行,这意味着您在添加std::endl
时忘记重新编译,或者您已经放错了位置。
我只是按你发布的方式运行了你的代码。endl
工作正常,命令行位于代码输出的下面。你显然是运行一个旧的二进制文件,从代码没有endl
还。仔细查看g++
调用中生成的文件的名称(在-o
之后的名称),以及它的位置。您可以尝试将您正在运行的可执行文件重命名为其他名称,并运行g++
以查看是否生成了具有您期望的名称的新文件。
就像前面提到的,确保您的代码中有using namespace std
和#include <iostream>
。
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- 将值从二维数组输出到文本文件
- 集合上的输出迭代器:assign和increment迭代器
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 为什么rk4.do_step不输出C++中的初始条件
- 输出没有重复元素的动态数组(收缩数组)C++
- 使用g++的c++输出中的额外细节