function help plz
I have an error (big surprise)
It says "conversion from 'string' to non-scalar type 'ifstream' requested."
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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
// Margaret Xu Programming 1A/B - C++
/*************************************************************
Create a file to array with strings instead of integers.
Project Name: file to array 2
Source code Name: Margaret Xu_file to array 2.cpp
Executable Name: Margaret Xu_file to array 2.exe
**************************************************************/
// Various Libraries
#include <iostream.h>
#include <string>
#include <iomanip.h>
#include <fstream.h>
#include <stdlib.h>
#include <math.h>
#include <vector.h>
// Create variables
using namespace std;
// Function Prototypes
void open_input_file (ifstream &in_file);
int main()
{
string MyName = ("Margaret Xu");
int student_id = 911735;
string date = ("April 18, 2008");
string name;
cout << "Welcome to " << MyName << "'s File to Array program" << endl;
int counter = 0;
ifstream input;
input.open ("List_of_Grades.txt");
int size;
// vector <string> name (size);
while (counter < size)
{
input >> name [counter];
counter++;
}
for (counter = 0; counter < size; counter++)
{
input >> name [counter];
cout << name [counter] << endl;
}
while (!input.eof ())
{
// getline (name);
}
string in_file_name;
open_input_file (in_file_name);
input.close ();
cout << "This program was written by " << MyName;
cout << ": " << student_id << " on " << date << "." << endl;
// The input stream must be flushed before calling the getline() function
cin.ignore(80, '\n');
cin.get();
system("Pause");
return 0;
}
void open_input_file (ifstream &in_file)
{
string in_file_name;
cout << "Enter the input file name: ";
cin >> in_file_name;
in_file.open (in_file_name.c_str());
assert (! in_file.fail());
return;
}
|
I don't really get it, and my teacher isn't helping by being absent.
Please help. Thx =]
never mind. The program works. =P
Topic archived. No new replies allowed.