Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 22, 2011, 02:24 AM   #1
chunhohuen
macrumors newbie
 
Join Date: Apr 2011
C++ new hand problem 2 please help (about library)

HI everyone, First I want to thanks all the help in here to solve my previous problem! It mains a lot to me!

Now, I would like to use the preivous program to build a static library and try to test it.

When I finish build the library and apply it for test, there are run times error occured:

1>fortest.obj : error LNK2019: unresolved external symbol "public: void __thiscall login::find(void)" (?find@login@@QAEXXZ) referenced in function _main

There are four of them and I know they are the same things.

I do not know how to fix them....


The code:

The header file is :

#include <fstream>
#include <string>

class login
{
public:
void setuser();

void write();

void read();

void find();

private:
char inputusername[99];
};

The code file is :


void find()

{
ifstream file;
file.open("file.txt");

string input=inputusername;
string input_line;
bool found = false;

while( file >> input_line ) {
if( input_line.compare(input) == 0 ) {
cout << "The name " << input_line << " was found in file.\n";
found = true;
break;
}
}

if( found == false ) {
ofstream fout ("file.txt",ios::app);
fout<<inputusername<<endl;
fout.close();
}

file.close();

}

void setuser() //function of set the username
{
cout<<"Enter the username: "<<endl;
cin>>inputusername;
int score=0;
}


void read() //read the file and show the details
{
cout<<endl;
ifstream fin("file.txt");
char ch;
while (fin.get(ch))
cout<<ch;
fin.close();
}



void write() //read the input to the file
{
ofstream fout ("file.txt",ios::app);
fout<<inputusername<<endl;
fout.close();
}


And the main test cpp file is:

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


int main()
{
login open;

int choice=0, number=0;

bool entered=false;
do {
cout <<endl;
cout << "Please choose an option below:\n\n";
cout << "1. input\n";
cout << "2. write\n";
cout << "3. read\n";
cout << "4. find\n";
cout << "5. Quit\n";
cin >> choice;


switch(choice) {
case (1) : {open.setuser();break;}


case (2) : {open.write(); break; }


case (3) : {open.read(); break; }


case (4) : {open.find(); break; }


case (5) : {break; }


}
}
while(choice != 5);

return 0;
}
chunhohuen is offline   0 Reply With Quote
Old Apr 22, 2011, 05:10 AM   #2
SidBala
macrumors 6502a
 
Join Date: Jun 2010
Where you define the code, you need to put in classname::functionname

Do this for every function you define. This need not be done if you are within the class declaration.

Code:
void login::find()
{
ifstream file;
file.open("file.txt");

string input=inputusername;
string input_line;
bool found = false;

while( file >> input_line ) {
if( input_line.compare(input) == 0 ) {
cout << "The name " << input_line << " was found in file.\n";
found = true;
break;
}
}
SidBala is offline   0 Reply With Quote
Old Apr 22, 2011, 07:32 AM   #3
Sander
macrumors 6502
 
Join Date: Apr 2008
I'm surprised this compiles (i.e. that you only get errors when linking). The line

Code:
string input=inputusername;
must have thrown an error at you, since "inputusername" is not visible to functions outside the class.
Sander is offline   0 Reply With Quote
Old Apr 22, 2011, 08:05 AM   #4
chunhohuen
Thread Starter
macrumors newbie
 
Join Date: Apr 2011
Quote:
Originally Posted by Sander View Post
I'm surprised this compiles (i.e. that you only get errors when linking). The line

Code:
string input=inputusername;
must have thrown an error at you, since "inputusername" is not visible to functions outside the class.
Quote:
Originally Posted by SidBala View Post
Where you define the code, you need to put in classname::functionname

Do this for every function you define. This need not be done if you are within the class declaration.

Code:
void login::find()
{
ifstream file;
file.open("file.txt");

string input=inputusername;
string input_line;
bool found = false;

while( file >> input_line ) {
if( input_line.compare(input) == 0 ) {
cout << "The name " << input_line << " was found in file.\n";
found = true;
break;
}
}

Thank you very much !!
It can work now !

Last edited by chunhohuen; Apr 22, 2011 at 09:34 AM.
chunhohuen is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Problem with AT&T 3g on iPad 2 Please help. mcapanelli iPad Tips, Help and Troubleshooting 5 May 18, 2011 12:37 AM
C++ new hand problem 3 please help (about GUI Interface) chunhohuen Mac Programming 7 Apr 23, 2011 09:35 PM
C++ new hand problem please help chunhohuen Mac Programming 14 Apr 22, 2011 01:43 AM
PowerMac G5 Dual 2.7 fan problem - PLEASE HELP!!! powermac_daddy Macintosh Computers 3 Nov 19, 2005 01:01 PM
my mac wony load os 9.2.2 please help woodsy51 General Mac Discussion 0 Dec 9, 2002 10:09 AM


All times are GMT -5. The time now is 09:36 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC