0

why do i get undefined reference to error in my main with regards to isvalidname. It says undefined reference to...


in my isvalidname i check if they enter in first name, char ws and then last name. Then i want to print out everything that i have deleted on that line. i guess i could use getback() or putback() or store my string at the beginning.

MAIN

#include <iostream>
#include <fstream>
#include "line_test.h"
using namespace std;

int main()
{
    //open up file to be read 
    string input;
    ifstream in;
    cout<<"enter file name which needs to be opened\n";
    cin>>input;
    in.open(input.c_str());
    while(!in)
    {
        in.close();
        cout<<"the input textfile failed please reenter the file\n";
        in.clear();
        cin>>input;
        in.open(input.c_str());
    }
    cout<<"the file opened\n";
    //open up file to copy to
    string output;
    ofstream out;
    cout<<"enter file name which to copy to\n";
    cin>>output;
    out.open(output.c_str());
    while(!out)
    {
        out.close();
        cout<<"output file opening failed. Please reenter output file name\n";
        out.clear();
        cin>>output;
        out.open(output.c_str());
    }
    //processing of file
    line_test a;
    out<<a.getfirst3(in);
    
    //string inputline;
    
    while(!in.eof())
    {
        a.iscomment(in,out);
        a.islabel(in,out);
        a.isequal(in,out);
        a.isvalidname(in,out);
        /*
        getline(in,inputline);
        a.iscomment(in);
        a.islabel(in);
        a.isequal(in);
        a.is_space();
        a.isvalidname(in);*/
    }
    in.close();
    out.close();
    return 0;

}

INTERFACE

#ifndef LINE_TEST_H_INCLUDED
#define LINE_TEST_H_INCLUDED
#include <fstream>
#include <iostream>
using namespace std;
class line_test
{
    public:
    //void iscomment(ifstream& input,ofstream& output);
    //string inputline;
    //string inputline1;
    //void islabel(ifstream& input,ofstream& output);
    
    
    //first line of file
    string title_comments;
    //second line of file
    string title_comments1;
    //third line of file
    string title_comments2;
    //first three lines of code
    string first_three_lines;
    string getfirst3(ifstream& input);
    
    void iscomment(ifstream& input,ofstream& output);
    void islabel(ifstream& input,ofstream& output);
    void isequal(ifstream& input,ofstream& output);
    void isvalidname(ifstream& input,ofstream& output);
    //void is_space();    
    //every line other than comment lines
    string inputline;
    string inputline3;
    string inputline2;
    //store everything that except for label in this string
    //string inputline2;
    //
    //string inputline3;
    //used to see if finds label or not
    
    //void isequal(ifstream& input);
    //string isvalid_entry(ifstream& input);*/
};



#endif // LINE_TEST_H_INCLUDED

IMPLEMENTATION

#include <iostream>
#include <fstream>
#include "line_test.h"
using namespace std;

//retrieve first 3 lines
string line_test::getfirst3(ifstream& input)
{
    string newline="\n";
    getline(input,title_comments);
    getline(input,title_comments1);
    getline(input,title_comments2);
    title_comments=title_comments+newline;
    title_comments1=title_comments1+newline;
    title_comments2=title_comments2+newline;
    first_three_lines=title_comments+title_comments1+title_comments2;
    return first_three_lines;
}
/*
void line_test::iscomment(ifstream& input,ofstream& output)
{
    if(input.peek()=='#')
    {
        getline(input,inputline);
        int length=inputline.length();
        input.ignore(0,length);
        output<<"";
    }
    else
    {
        getline(input,inputline);
        //output<<inputline<<"\n";
    }
}

void islabel(ifstream& input,ofstream& output)
{
    //string inputline1;
    if(input.peek('n'))
    {
        //getline(input,inputline1);
        input.ignore(0,4);
        output<<inputline;
    }
    else
    {
        output<<"nothing";
    }
}

*/


//function used to check if there are comments

void line_test::iscomment(ifstream& input,ofstream& output)
{
    getline(input,inputline);
    if(inputline.find('#')==0)
    {
        int length=inputline.length();
        inputline.erase(0,length);
        input.ignore(0,length);
        output<<"";
    }
    else
    {
        //output<<inputline<<"\n";
    }
}

//checks if data is labeled correctly
void line_test::islabel(ifstream& input,ofstream& output)
{
    if(inputline.find("name")==0)
    {
        inputline.erase(0,4);
        input.ignore(0,4);
        //output<<inputline<<"\n";
        //cout<<"name"<<inputline2<<"\n";
    }
    
    else if(inputline.find("ID")==0)
    {
        inputline.erase(0,2);
        input.ignore(0,2);
        //output<<inputline<<"\n";
        //cout<<"id"<<inputline2<<"\n";
    }
    else if(inputline.find("GPA")==0)
    {
        inputline.erase(0,3);
        input.ignore(0,3);
        //output<<inputline<<"\n";
        //cout<<"gpa"<<inputline2<<"\n";
    }
    else if(inputline.find("gender")==0)
    {
        inputline.erase(0,6);
        input.ignore(0,6);
        //output<<inputline<<"\n";
        //cout<<"gender"<<inputline2<<"\n";
    }
    else
    {
        int length=inputline.length();
        inputline.erase(0,length);
        input.ignore(0,length);
        //output<<"";
    }
}

//check if their an equal sign 
void line_test::isequal(ifstream& input,ofstream& output)
{

    while(inputline.find(' ')==0||inputline.find('=')==0) //I changed inputline2 to inputline and it worked fine.
    {
            //output<<"input is"<<inputline2<<"\n";
            
            inputline.erase(0,1);
            input.ignore(0,1);
    }
    //output<<inputline<<"\n";
}
void isvalidname(ifstream& input,ofstream& output)
{
    
    string first_name;
    char ws;
    string last_name;
    if(input>>first_name>>ws>>last_name)
    {
        output<<first_name<<ws<<last_name;
    }
}
1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by lotrsimp12345
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.