麻烦帮看下这个程序错在什么地方
时间:2011-11-29
来源:互联网
//StrType.h#include <fstream>#include <iostream>#include <cstring> const int MAX_CHARS=100;enum InType {ALPHA_NUM, ALPHA, NON_WHITE, NOT_NEW}; class StrType{public: void MakeEmpty(); void GetString(bool skip, InType charsAllowed); void GetStringFile(bool skip, InType charsAllowed, std::ifstream& inFile); void PrintToScreen(bool newLine); void PrintToFile(bool newLine, std::ofstream& outFile); int LenghtIs(); void CopyString(StrType& newString); bool operator==(const StrType& rhs) const { return strcmp(letters, rhs.letters) == 0; } bool operator<(const StrType& rhs) const { return strcmp(letters, rhs.letters) < 0; }private: char letters[MAX_CHARS + 1];}; void StrType::MakeEmpty(){ letters[0] ='\0';}//StrType.h
#include <fstream>
#include <iostream>
#include <cstring>
const int MAX_CHARS=100;
enum InType {ALPHA_NUM, ALPHA, NON_WHITE, NOT_NEW};
class StrType
{
public:
void MakeEmpty();
void GetString(bool skip, InType charsAllowed);
void GetStringFile(bool skip, InType charsAllowed,
std::ifstream& inFile);
void PrintToScreen(bool newLine);
void PrintToFile(bool newLine, std::ofstream& outFile);
int LenghtIs();
void CopyString(StrType& newString);
bool operator==(const StrType& rhs) const
{
return strcmp(letters, rhs.letters) == 0;
}
bool operator<(const StrType& rhs) const
{
return strcmp(letters, rhs.letters) < 0;
}
private:
char letters[MAX_CHARS + 1];
};
void StrType::MakeEmpty()
{
letters[0] ='\0';
}
//main.cpp#include <fstream>#include "StrType.h"#include <cstddef>#include <iostream>#include <string>using namespace std; struct WordType{ public: StrType word; int count;}; struct TreeNode{ WordType info; TreeNode* left; TreeNode* right;}; class ListType{ public: ListType(); void InsertOrIncrement (StrType string); void Print(std::ofstream&) const; private: TreeNode* root;}; ListType::ListType(){ root=NULL;} void Process(TreeNode*& tree, StrType s){ if(tree == NULL) { tree = new TreeNode; tree->info.word = s; tree->info.count = 1; tree->left = NULL; tree->right = NULL; } else if (tree->info.word == s) tree->info.count++; else if (s < tree->info.word) Process(tree->left, s); else Process(tree->right, s);} void ListType::InsertOrIncrement(StrType s){ Process(root, s);} void Print (TreeNode* tree, std::ofstream& outFile){ if (tree!= NULL) { Print(tree->left, outFile); tree->info.word.PrintToFile(true, outFile); outFile <<" "<< tree->info.count; Print(tree->right, outFile); }} void ListType::Print(std::ofstream& outFile) const{ ::Print(root, outFile);} int main(){ using namespace std; ListType list; string inFileName; string outFileName; string outputLabel; ifstream inFile; ofstream outFile; StrType string; int minimumLenght; cout<<"enter in imput file name."<<endl; cin>>inFileName; inFile.open(inFileName.c_str()); cout<<"enter name of output file."<<endl; cin>>outFileName; outFile.open(outFileName.c_str()); cout<<"enter name of test run."<<endl; cin>>outputLabel; outFile<< outputLabel << endl; cout<<"enter the min word size."<<endl; cin>>minimumLenght; string.GetStringFile(true, ALPHA_NUM, inFile); while(inFile) { if(string.LenghtIs() >= minimumLenght) list.InsertOrIncrement(string); string.GetStringFile(true, ALPHA_NUM, inFile); } list.Print(outFile); outFile.close(); inFile.close(); return 0;} //main.cpp
#include <fstream>
#include "StrType.h"
#include <cstddef>
#include <iostream>
#include <string>
using namespace std;
struct WordType
{
public:
StrType word;
int count;
};
struct TreeNode
{
WordType info;
TreeNode* left;
TreeNode* right;
};
class ListType
{
public:
ListType();
void InsertOrIncrement (StrType string);
void Print(std::ofstream&) const;
private:
TreeNode* root;
};
ListType::ListType()
{
root=NULL;
}
void Process(TreeNode*& tree, StrType s)
{
if(tree == NULL)
{
tree = new TreeNode;
tree->info.word = s;
tree->info.count = 1;
tree->left = NULL;
tree->right = NULL;
}
else if (tree->info.word == s)
tree->info.count++;
else if (s < tree->info.word)
Process(tree->left, s);
else
Process(tree->right, s);
}
void ListType::InsertOrIncrement(StrType s)
{
Process(root, s);
}
void Print (TreeNode* tree, std::ofstream& outFile)
{
if (tree!= NULL)
{
Print(tree->left, outFile);
tree->info.word.PrintToFile(true, outFile);
outFile <<" "<< tree->info.count;
Print(tree->right, outFile);
}
}
void ListType::Print(std::ofstream& outFile) const
{
::Print(root, outFile);
}
int main()
{
using namespace std;
ListType list;
string inFileName;
string outFileName;
string outputLabel;
ifstream inFile;
ofstream outFile;
StrType string;
int minimumLenght;
cout<<"enter in imput file name."<<endl;
cin>>inFileName;
inFile.open(inFileName.c_str());
cout<<"enter name of output file."<<endl;
cin>>outFileName;
outFile.open(outFileName.c_str());
cout<<"enter name of test run."<<endl;
cin>>outputLabel;
outFile<< outputLabel << endl;
cout<<"enter the min word size."<<endl;
cin>>minimumLenght;
string.GetStringFile(true, ALPHA_NUM, inFile);
while(inFile)
{
if(string.LenghtIs() >= minimumLenght)
list.InsertOrIncrement(string);
string.GetStringFile(true, ALPHA_NUM, inFile);
}
list.Print(outFile);
outFile.close();
inFile.close();
return 0;
}
#include <fstream>
#include "StrType.h"
#include <iostream>
#include <string>
#include <cctype>
#include <cstring>
using namespace std;
// Prototypes of auxiliary function.
void GetAlphaNum(bool skip, char letters[]);
// Post: letters array contains only alphabetic characters and numbers.
void StrType::GetString(bool skip, InType charsAllowed)
{
switch (charsAllowed)
{
case ALPHA_NUM : GetAlphaNum(skip, letters);
break;
//commented out:
// case ALPHA : GetAlpha(skip, letters);
// break;
// case NON_WHITE : GetNonWhite(skip, letters);
// break;
// case NOT_NEW : GetTilNew(skip, letters);
// break;
}
}
void StrType::CopyString(StrType& newString)
{
strcpy(newString.letters, letters);
}
void StrType::PrintToScreen(bool newLine)
{
if (newLine)
cout << endl;
cout << letters;
}
void StrType::MakeEmpty()
{
letters[0] = '\0';
}
int StrType::LengthIs()
{
return strlen(letters);
}
//note that this is NOT a member function of the StrType class.
//It's a global function that is called by some member functions.
void GetAlphaNum(bool skip, char letters[])
{
char letter;
int count = 0;
if (skip)
{
cin.get(letter);
while (!isalnum(letter) && cin)
cin.get(letter);
}
else
cin.get(letter);
if (!cin || !isalnum(letter))
letters[0] = '\0';
else
{
do
{
letters[count] = letter;
count++;
cin.get(letter);
} while (isalnum(letter) && cin && (count < MAX_CHARS));
letters[count] = '\0';
// Skip extra characters if necessary.
if (count == MAX_CHARS)
do
{
cin.get(letter);
} while (isalnum(letter) && cin);
}
}
错误是undefined reference to `StrType::PrintToFile(bool, std::basic_ofstream<char, st
d::char_traits<char> >&)'
undefined reference to `StrType::GetStringFile(bool, InType, std::basic_ifstrea
m<char, std::char_traits<char> >&)'
undefined reference to `StrType::LenghtIs()'
undefined reference to `StrType::GetStringFile(bool, InType, std::basic_ifstrea
m<char, std::char_traits<char> >&)'
collect2: ld returned 1 exit status
#include <fstream>
#include <iostream>
#include <cstring>
const int MAX_CHARS=100;
enum InType {ALPHA_NUM, ALPHA, NON_WHITE, NOT_NEW};
class StrType
{
public:
void MakeEmpty();
void GetString(bool skip, InType charsAllowed);
void GetStringFile(bool skip, InType charsAllowed,
std::ifstream& inFile);
void PrintToScreen(bool newLine);
void PrintToFile(bool newLine, std::ofstream& outFile);
int LenghtIs();
void CopyString(StrType& newString);
bool operator==(const StrType& rhs) const
{
return strcmp(letters, rhs.letters) == 0;
}
bool operator<(const StrType& rhs) const
{
return strcmp(letters, rhs.letters) < 0;
}
private:
char letters[MAX_CHARS + 1];
};
void StrType::MakeEmpty()
{
letters[0] ='\0';
}
//main.cpp#include <fstream>#include "StrType.h"#include <cstddef>#include <iostream>#include <string>using namespace std; struct WordType{ public: StrType word; int count;}; struct TreeNode{ WordType info; TreeNode* left; TreeNode* right;}; class ListType{ public: ListType(); void InsertOrIncrement (StrType string); void Print(std::ofstream&) const; private: TreeNode* root;}; ListType::ListType(){ root=NULL;} void Process(TreeNode*& tree, StrType s){ if(tree == NULL) { tree = new TreeNode; tree->info.word = s; tree->info.count = 1; tree->left = NULL; tree->right = NULL; } else if (tree->info.word == s) tree->info.count++; else if (s < tree->info.word) Process(tree->left, s); else Process(tree->right, s);} void ListType::InsertOrIncrement(StrType s){ Process(root, s);} void Print (TreeNode* tree, std::ofstream& outFile){ if (tree!= NULL) { Print(tree->left, outFile); tree->info.word.PrintToFile(true, outFile); outFile <<" "<< tree->info.count; Print(tree->right, outFile); }} void ListType::Print(std::ofstream& outFile) const{ ::Print(root, outFile);} int main(){ using namespace std; ListType list; string inFileName; string outFileName; string outputLabel; ifstream inFile; ofstream outFile; StrType string; int minimumLenght; cout<<"enter in imput file name."<<endl; cin>>inFileName; inFile.open(inFileName.c_str()); cout<<"enter name of output file."<<endl; cin>>outFileName; outFile.open(outFileName.c_str()); cout<<"enter name of test run."<<endl; cin>>outputLabel; outFile<< outputLabel << endl; cout<<"enter the min word size."<<endl; cin>>minimumLenght; string.GetStringFile(true, ALPHA_NUM, inFile); while(inFile) { if(string.LenghtIs() >= minimumLenght) list.InsertOrIncrement(string); string.GetStringFile(true, ALPHA_NUM, inFile); } list.Print(outFile); outFile.close(); inFile.close(); return 0;} //main.cpp
#include <fstream>
#include "StrType.h"
#include <cstddef>
#include <iostream>
#include <string>
using namespace std;
struct WordType
{
public:
StrType word;
int count;
};
struct TreeNode
{
WordType info;
TreeNode* left;
TreeNode* right;
};
class ListType
{
public:
ListType();
void InsertOrIncrement (StrType string);
void Print(std::ofstream&) const;
private:
TreeNode* root;
};
ListType::ListType()
{
root=NULL;
}
void Process(TreeNode*& tree, StrType s)
{
if(tree == NULL)
{
tree = new TreeNode;
tree->info.word = s;
tree->info.count = 1;
tree->left = NULL;
tree->right = NULL;
}
else if (tree->info.word == s)
tree->info.count++;
else if (s < tree->info.word)
Process(tree->left, s);
else
Process(tree->right, s);
}
void ListType::InsertOrIncrement(StrType s)
{
Process(root, s);
}
void Print (TreeNode* tree, std::ofstream& outFile)
{
if (tree!= NULL)
{
Print(tree->left, outFile);
tree->info.word.PrintToFile(true, outFile);
outFile <<" "<< tree->info.count;
Print(tree->right, outFile);
}
}
void ListType::Print(std::ofstream& outFile) const
{
::Print(root, outFile);
}
int main()
{
using namespace std;
ListType list;
string inFileName;
string outFileName;
string outputLabel;
ifstream inFile;
ofstream outFile;
StrType string;
int minimumLenght;
cout<<"enter in imput file name."<<endl;
cin>>inFileName;
inFile.open(inFileName.c_str());
cout<<"enter name of output file."<<endl;
cin>>outFileName;
outFile.open(outFileName.c_str());
cout<<"enter name of test run."<<endl;
cin>>outputLabel;
outFile<< outputLabel << endl;
cout<<"enter the min word size."<<endl;
cin>>minimumLenght;
string.GetStringFile(true, ALPHA_NUM, inFile);
while(inFile)
{
if(string.LenghtIs() >= minimumLenght)
list.InsertOrIncrement(string);
string.GetStringFile(true, ALPHA_NUM, inFile);
}
list.Print(outFile);
outFile.close();
inFile.close();
return 0;
}
#include <fstream>
#include "StrType.h"
#include <iostream>
#include <string>
#include <cctype>
#include <cstring>
using namespace std;
// Prototypes of auxiliary function.
void GetAlphaNum(bool skip, char letters[]);
// Post: letters array contains only alphabetic characters and numbers.
void StrType::GetString(bool skip, InType charsAllowed)
{
switch (charsAllowed)
{
case ALPHA_NUM : GetAlphaNum(skip, letters);
break;
//commented out:
// case ALPHA : GetAlpha(skip, letters);
// break;
// case NON_WHITE : GetNonWhite(skip, letters);
// break;
// case NOT_NEW : GetTilNew(skip, letters);
// break;
}
}
void StrType::CopyString(StrType& newString)
{
strcpy(newString.letters, letters);
}
void StrType::PrintToScreen(bool newLine)
{
if (newLine)
cout << endl;
cout << letters;
}
void StrType::MakeEmpty()
{
letters[0] = '\0';
}
int StrType::LengthIs()
{
return strlen(letters);
}
//note that this is NOT a member function of the StrType class.
//It's a global function that is called by some member functions.
void GetAlphaNum(bool skip, char letters[])
{
char letter;
int count = 0;
if (skip)
{
cin.get(letter);
while (!isalnum(letter) && cin)
cin.get(letter);
}
else
cin.get(letter);
if (!cin || !isalnum(letter))
letters[0] = '\0';
else
{
do
{
letters[count] = letter;
count++;
cin.get(letter);
} while (isalnum(letter) && cin && (count < MAX_CHARS));
letters[count] = '\0';
// Skip extra characters if necessary.
if (count == MAX_CHARS)
do
{
cin.get(letter);
} while (isalnum(letter) && cin);
}
}
错误是undefined reference to `StrType::PrintToFile(bool, std::basic_ofstream<char, st
d::char_traits<char> >&)'
undefined reference to `StrType::GetStringFile(bool, InType, std::basic_ifstrea
m<char, std::char_traits<char> >&)'
undefined reference to `StrType::LenghtIs()'
undefined reference to `StrType::GetStringFile(bool, InType, std::basic_ifstrea
m<char, std::char_traits<char> >&)'
collect2: ld returned 1 exit status
作者: ynqjxq66 发布时间: 2011-11-29
这样的代码,,。。。
作者: mingliang1212 发布时间: 2011-11-29
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28