I am trying to drag a program originally written in Borland C version 3 into the light of the present using Visual C++ 2010.
I have a curious, apparently simple, problem.
The program read data from a file.
I can create a noddy program that opens and reads the contents of a file.
However, when I transfer that code into the program to be converted it complains about the getline function.
The noddy program is
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <conio.h>
#include <ctype.h>
#include <direct.h>
#include <stdio.h>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char* path = "c:\\DrugData\\DrugData.txt";
string line;
ifstream myfile (path);
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
}
but when used in the converted program
strcpy_s(filename, "C;:\\DrugData\\DrugData.txt");
ifstream fp(filename);
getline(fp, buffer);
I get the error message:
c:\users\norman\documents\visual studio 2010\projects\drug1\drug1\drug1.cpp(114): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream'
1> c:\program files\microsoft visual studio 10.0\vc\include\string(479) : see declaration of 'std::getline'
In case you're worried about the drug reference, I am diabetic and take a lot of pills to control it, and the program helps me maintain control over the quantities of pills I have left.