C++ 将数组元素向右推送
c++ pushing array elements to the right
我是编程新手,有这个 c++ 学校测验。
我想将输入的数组元素推到右侧。
这是我现有的代码
块引用
// automatac++.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <list>
#include <iterator>
#include <conio.h>
#include <cstring>
//using namespace std;
using std::cout;
using std::cin;
using std::endl;
void menu_sel();
void push_element();
//void rem_element();
int in;
char array[100];
int p_elements;
int main()
{
menu_sel();
return 0;
}
void push_element() {
int p_elements;
for (int e = 0; e < 10; e++) {
}
cout << "Enter number of elements:";
cin >> p_elements;
cout << "Enter only " << p_elements << " elements"<<endl;
for (int e = 0; e < p_elements; e++ ) {
cin >> array[e];
}
cout << "Pushed elements are :";
for (int e = 0; e < p_elements; ++e) {
cout << array[e]<<" ";
}
//getch();
menu_sel();
}
/*
void rem_element() {
char remove;
int arr_position;
cout << "You have selected Pop.nRemove elements from arrays n";
cout << "Enter data to remove";
cin >>remove;
for (int ie -) {
}
system("pause");
}
*/
void menu_sel() {
int input;
cout << "n****Menu Selection Here****";
cout << "n1. Push n2. Pop n3. Exit n";
cout << "select options here :";
cin >> input;
switch (input) {
case 1:
cout << "You have selected Push Stackn";
push_element();
break;
case 2:
//cout << "You have selected Pop Stackn";
//rem_element();
break;
default:
cout << "You have selected Invalid Options";
break;
system("cls");
return;
}
}
这是输出
输出显示将元素向左推送
输出为 3 E R 4
我想显示这样的输出"4 r e 3">
感谢和问候,
如果你想以这种方式显示数组,你总是可以向后读取数组以进行输出。
for (int e = p_elements-1; e >= 0; --e) {
cout << array[e]<<" ";
}
相关文章:
- 数组元素打印的递归方法
- 如何将字节数组元素替换为修改的十六进制 ASCII 符号?
- 为什么使用数组元素查找最大数字的程序不起作用?
- 数组元素更改值?
- 如何访问宏中定义的数组元素
- 将数组元素递增 1
- C++函数,它将数组、谓词和运算符作为参数,并将运算符应用于满足谓词的数组元素
- 存储指向动态数组元素的指针
- C++通过别名指针以静默方式将错误的类型分配给数组元素
- 在 std::map 中插入数组元素
- 使用指针访问数组元素时出现意外结果
- c++ 使用动态分配运算符反向数组元素
- 为什么在 c++ 中分配 char 数组元素时,分配的字符会被销毁?
- 缺少数组元素问题
- 如何在类中制作 2D 数组元素,然后在其构造函数中指定其维度?
- 创建一个函数来转换数组元素的类型并返回数组的地址
- 删除在结构 c++ 中声明的数组元素
- Getter 和 Setter 用于类 C++ 中的数组元素
- 尝试递归获取数组元素的总和
- 使用SWIG将numpy数组元素(int)传递给c++int