I am receiving this message on my ms visual 2013 Error 1 error LNK2019: unresolv
ID: 3786612 • Letter: I
Question
I am receiving this message on my ms visual 2013 Error 1 error LNK2019: unresolved external symbol "void __cdecl displayLastLine(class std::basic_ifstream > &)" (?displayLastLine@@YAXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _main What does it mean
Punch Line: Write a program that reads and prints a joke and its punch line from two different files. The first file contains a joke. The second file has the punchline as its last line, preceded by "garbage text". Note the last sentence will have a newline character before it. The program is to search for the start of the last sentence not move backward from the file a fixed number of characters. The main only opens the files and calls the functions. The first function reads and displays the joke. The second finds and displays the last line.
functions void displayAllLines(ifstream &infile) & void displayLastLine(ifstream &infile)
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void displayAllLines(ifstream &infile);
void displayLastLine(ifstream &infile);
int main()
{
ifstream joke;
ifstream punchLine;
cout << "I heard this joke on the radio on the way to work this morning. ";
cout << "It's pretty corny but for some reason I found it to be LoL! ";
joke.open("C:\Users\Anna\Desktop\joke.txt", ios::in);
punchLine.open("C:\Users\Anna\Desktop\punchline.txt", ios::in);
if (joke)
{
displayAllLines(joke);
}
else
cout << "There was an error opening the file. ";
if (punchLine)
{
displayLastLine(punchLine);
}
else
cout << "There was an error opening the file. ";
joke.close();
punchLine.close();
system("pause");
return 0;
}
void displayAllLines(ifstream &infile)
{
string line;
getline(infile, line);
while (infile)
{
cout << line << " ";
getline(infile, line);
}
}
void displayLasttLine(ifstream &infile)
{
string line;
char ch;
long pos = -1;
infile.seekg(0L, ios::end);
infile.seekg(pos, ios::cur);
infile.get(ch);
while (ch != ' ')
{
pos--;
infile.seekg(pos, ios::cur);
infile.get(ch);
}
getline(infile, line);
if (infile)
cout << line << endl;
}
Explanation / Answer
unike java, C and C++ both are case- sensitive.As shown above program we decalre the function as displayLasttline()
and displayLasttline(). In C++ compiler doesnot match those two.so you got that eror.Instead you use same function name in two decalrations.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.