compiling error

Hi, can someone please identify my error? cause I can not detect my own error. Apparently the error is at cin >> RegNo. What is wrong with that?


#include <fstream>
#include <iostream>

using namespace std;

int main()
{
int RegNo[9];
float AssignmentMark[2];
char FileName[20];

cout << "Enter student registration number: ";
cin >> RegNo;


cout << "Enter assignmark mark: ";
cin >> AssignmentMark;

cout << "\nEnter the name of the file you want to create: ";
cin >> FileName;
ofstream Student(FileName, ios::out);
Student << RegNo << " " << AssignmentMark;
return 0;
}
You can't read into arrays like that. You have to read into a particular int, so something like cin>>RegNo[0]; would work.
There're three things I'm not sure about your variables.

Why are you allocating arrays in each case? In the case of an int, you don't need an array because int stores numbers ranging from about -2 billion to +2 billion, not single digits.

The same goes for float. It doesn't store individual digits, it stores entire numbers, although I don't remember the range. For something like grades, though, it'll work fine, so... :)

Also, in place of your char[] you can use a string after #include/*ing*/ <string> . Not only is it much safer, but you don't have to specify how long your string will be.

-Albatross
Last edited on
Ok, actually I want to specify the RegNo into 10 digits longs number which the number will belong to the group of 0-9.

Will assigning the RegNo into an array of RegNo[9] is possible?
You could do that, but you might as well use int64_t. It can hold numbers between -2^63 and 2^63.
alright.. thanks guys for the info..
Topic archived. No new replies allowed.