Reputation: 3737
So I'm trying to create a C++ program that reads in a list of numbers(where the user enters a list of 5 numbers separated by spaces) and prints out the reversed list. so far, this is what I have:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#pragma warning(disable: 4996)
using namespace std;
int* get_Number() {
int* p = new int[32];
cout << "Please enter a list of 5 numbers, separated by spaces" << endl;
cin >> p;
return p;
};
int* reverseArray(int* numArray)
{
}
My problem is that I keep on getting this error:
Error: no operator ">>" matches these operands. Operand types are: std::istream >> int *
at the cin >> p
line.
What am I doing wrong? I'm new to C++, and any help would be greatly appreciated, thank you!!
Upvotes: 1
Views: 168
Reputation: 194
How about this?
#include <iostream>
int main(int argc, char* argv[])
{
int nums[5];
std::cout << "Please enter a list of 5 numbers, separated by spaces" << std::endl;
for (int i = 0; i < 5; ++i)
std::cin >> nums[i];
for (int i = 0; i < 5; ++i)
std::cout << nums[i];
return 0;
}
Upvotes: 2
Reputation: 1811
Did you mean cin >> p[i]
, where i
is an index missing in your code?
Currently you're reading to a pointer, but you intended to read into your array, right?
Try this
int* get_Number() {
int* p = new int[32];
for (int i = 0; i < 5; i++)
{
cout << "Please enter a number" << endl;
cin >> p[i];
}
return p;
};
Upvotes: 1
Reputation: 76346
You're better off using getline
string line;
cin.getline(line);
It will do nice stuff for you like resizing it.
Upvotes: 1