Nov 4, 2012 at 1:39am UTC
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
bool Open_InputFile (ifstream &fin)
{
string file_name;
cout << "Enter Input File Name: " ;
getline (cin, file_name);
fin.open(file_name.c_str());
if (fin.fail())
return false ;
else
return true ;
}
int Read_WaitTime (ifstream &fin, string bank_name[], double w_time[], int size, int banksize)
{
int i = 0;
if (Open_InputFile(fin))
{
cout << "File Opened\n" ;
Read_BankName(fin, bank_name, banksize);
fin >> w_time [i];
while (!fin.eof())
{
i++;
if (i == size)
break ;
fin >> w_time [i];
}
fin.close();
}
else
{
cout << "\nBAD FILE NAME!\n " << endl;
return 0;
}
return i;
}
int Read_BankName (ifstream &fin, string bank_name[], int banksize)
{
int k = 0;
getline (fin, bank_name[k]);
return k;
}
I got confused on how to actually open 10 files? since in my code it could only read 1 file. Thank you.
Last edited on Nov 4, 2012 at 2:17am UTC
Nov 4, 2012 at 2:06am UTC
before writing your code please use
[ c o d e ]
tag w/o spaces and while ending code use
[ / c o d e ]
w/o spaces. So its easily understandable and people will try to read and help you.
Nov 4, 2012 at 3:11am UTC
I only include
#include<iostream>
#include<fstream>
#include<string>
what is to_string(i) mean? could you explain a little bit.
Also, actually is not CREATING A FILE instead I supposed to READ 10 input text files given.
Thank you for your help
Nov 4, 2012 at 3:28am UTC
to_string(i) converts numerical value 'i' to string.
This function is added to <string> under C++11.
You must use
g++ filename.cpp -std=c++0x
to compile.
And this is just an example, you can set it up for your own use.
You can see more details here.
http://en.cppreference.com/w/cpp/string/basic_string/to_string
Last edited on Nov 4, 2012 at 3:29am UTC