My program compiles, but fail to build when I use "template <class T>". The error I recieved is "LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main". I google the error read articles about console applications vs. win23 applications. I have re-created my environment for win23 application and I am still getting the build error. Can someone please assist.
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <vector>
using namespace std;
template <class T>
int main()
{
string fileName,line;
ifstream infile;
cout<<"Enter the file name and complete path: ";
cin>>fileName;
std::vector<string> A;
infile.open(fileName.c_str());
while(!infile.eof())
{
getline(infile,line);
if(line[count]=='A'||line[count]=='a')
{
A.push_back(line);
A[Aa]=line;
cout<<A[Aa]<<endl;
Aa++;
}
}
infile.close();
return 0;
}
I am simply trying to follow the recommendation you gave me last night. I have never used this function before. Where exactly should mt template be? Do i need to delete "int main ()"? I am totally lost.
...what? I couldn't have... oh... wait... my advice was to use a vector, but I don't recall seeing my telling you to make main a template anywhere here: http://cplusplus.com/forum/general/24159/
You're not making a new template, see, so you don't need that line. In fact, it gets in your way, because main() can't be a template.
Also, I recall telling you that this line doesn't do what you think it does: if(line[count]=='A'||line[count]=='a')
Tiny hint: you want 0 in place of count, which, by the way, is not declared anywhere.
Also, Aa is not declared anywhere. You'll... need to do that.
If you do those, it should compile without problems.