I am new to C++. I am also new to arrays.
These are the istructions.
You are going to create an array of ints of size 10. You will then make a function with the following signature:
void readInts( string input, string output );
and this needs to be declared in a header called:
lab7.h
The function will read one numbers per line from the input. The first number will simply be stored in the array at the next available location. If the array is full, then you do not add the number to the array.
Once all the data has been read in and possibly stored in the array, you will loop over the array and give me the index location and the value stored there.
here's my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include "lab7.h"
void readInts( string input, string output )
{
ifstream in( input );
ofstream out( output );
int array [10];
int x = 0;
input.open();
while ( count < 10 && input >> array[10])
input.close();
out << "Index Value" << endl;
for ( x = 0; x < 10; x++ )
{
out << x << " " << array[x] << endl;
}
}
|
I keep getting these errors when I try to compile,
lab7.cpp
lab7.cpp(11): error C2039: 'open': is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char
>>'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xstring(2633): note: see declaration of 'std::basic_strin
g<char,std::char_traits<char>,std::allocator<char>>'
lab7.cpp(13): error C2677: binary '&&': no global operator found which takes type 'std::string' (or there is no acceptab
le conversion)
lab7.cpp(13): error C2563: mismatch in formal parameter list
lab7.cpp(15): error C2039: 'close': is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<cha
r>>'
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xstring(2633): note: see declaration of 'std::basic_strin
g<char,std::char_traits<char>,std::allocator<char>>'
testmain.cpp
Could someone help?
edit:
this is my header
1 2 3 4 5 6 7 8
|
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
using std::ifstream;
using std::ofstream;
void readInts( string input, string output );
|