Feb 19, 2009 at 7:42pm UTC
I am doing a project for school and I have to get information from a file. All is good when i write the code all in main, but that isn't very good coding. I have a very small knowledge of arrays and such as I am just beginning. I have coded in python so I know basic programming logic. Here's the code and the errors
using namespace std;
#include <string>
#include <iostream>
#include <fstream>
struct Tide
{
string Date;
string Time;
float Height;
};
void getData(string , Tide [], string& , string& )
int main()
{
const int MAX = 124;
string FileName;
string location;
string tideOfFirstLine;
Tide CompleteDataList[MAX];
/* cout << "\nEnter name of the file to recieve input from: ";
cin >> FileName;*/
getData( "/user/cse232/Projects/project05.data", CompleteDataList , location, tideOfFirstLine );
cout << location;
}
/*----------------------------------------------------------------------------
Get Data from file and build array with proper data also creating variablesi
for the place and which tide comes first.
Recieve: InFile (string), list[array], place[string], firstTide[string]
Return: place[string], firstTide[string]
-----------------------------------------------------------------------------*/
void getData(string InFile, Tide list[], string& place, string& firstTide)
{
Tide temp;
int Num = 0;
ifstream tideFile;
tideFile.open(InFile, ios::in);
getline(tideFile, place);
getline(tideFile, firstTide);
}
proj05.solution.cpp: In function 'void getData(std::string, Tide*, std::string&, std::string&)':
proj05.solution.cpp:64: error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::open(std::string&, const std::_Ios_Openmode&)'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/fstream:495: note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
Feb 19, 2009 at 7:50pm UTC
tideFile.open(InFile.c_str(), ios::in);
to fix your compile error
Feb 19, 2009 at 8:06pm UTC
I guess it was a pretty simple fix. Can you explain exactly what that does?