- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用链表来实现索引程序。尝试使用 g++ 编译程序时出现以下编译器错误:
concordancetest.cpp:在函数“void build_list(std::ifstream&, char*)”中:
concordancetest.cpp:65: 错误:没有匹配函数来调用‘Concordance::insert(char*&, int&)’
concordance.h:22: 注意:候选人是:void Concordance::insert(char (&)[9], int&)
下面是我写的代码:
头文件:
#ifndef CONCORDANCE_H
#define CONCORDANCE_H
#include <iostream>
#include <cstdlib>
const int MAX = 8;
class Concordance
{
public:
//typedef
typedef char Word[MAX+1];
//constructor
Concordance();
//destructor
~Concordance();
//modification member functions
void insert(Word& word, int& n);
void remove(Word& word);
int get_count(Word& word);
//constant member functions
int length() const;
//friend member functions
friend std::ostream& operator << (std::ostream& out_s, Concordance& c);
private:
struct Node
{
Word wd;
int count;
Node *next;
};
Node *first;
Node* get_node(Word& word, int& count, Node* link);
};
#endif
实现代码:
//class definition
#include "concordance.h"
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
Concordance::Concordance()
{
first = NULL;
}
Concordance::~Concordance()
{
Node *temp;
while(first != NULL)
{
temp = first;
first = first -> next;
delete temp;
}
}
void Concordance::insert(Word& word, int& n)
{
Node *prev;
if(first == NULL || strcmp(first -> wd, word) > 0)
first = get_node(word, n, first);
else
{
prev = first;
while(prev -> next != NULL && strcmp(prev -> next -> wd, word) > 0)
prev = prev -> next;
prev -> next = get_node(word, n, prev -> next);
}
}
void Concordance::remove(Word& word)
{
Node *prev, *temp;
prev = temp;
if(prev -> wd == word)
{
first = first -> next;
delete prev;
}
else
{
while(strcmp(prev -> next -> wd, word) > 0)
prev = prev -> next;
temp = prev -> next;
prev -> next = temp -> next;
delete temp;
}
}
int Concordance::get_count(Word& word)
{
while(strcmp(first -> wd, word) != 0)
first = first -> next;
return first -> count;
}
int Concordance::length() const
{
Node *cursor;
int len;
len = 0;
for(cursor = first; cursor != NULL; cursor = cursor -> next )
len++;
return len;
}
Concordance::Node* Concordance::get_node (Word& word, int& count, Node* link)
{
Node *temp;
temp = new Node;
strcpy(temp-> wd, word);
temp-> next = link;
temp -> count = count+1;
return temp;
}
ostream& operator << (ostream& out_s, Concordance& c)
{
Concordance::Node *cursor;
out_s << "Word" << setw(10) << " " << "Count" << endl;
out_s << "--------------------" << endl;
for(cursor = c.first; cursor != NULL && cursor->next != NULL; cursor = cursor-> next )
out_s << cursor-> wd << setw(10) << " " << cursor -> count << endl;
if(cursor != NULL)
out_s << cursor-> wd << setw(10) << " " << cursor -> count << endl;
out_s << "--------------------" << endl;
return out_s;
}
测试程序:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include "concordance.h"
using namespace std;
void read_word(ifstream& in_file, char array[]);
void build_list(ifstream& in_file, char array[]);
int main()
{
char file_name[100];
ifstream in_file;
char array[MAX+1];
cout << "Enter a file name: ";
cin >> file_name;
in_file.open(file_name);
build_list(in_file, array);
in_file.close();
return EXIT_SUCCESS;
}
void read_word(ifstream& in_file, char array[])
{
char ch;
int i = 0;
in_file.get(ch);
while(isalpha(ch) && !isspace(ch))
{
if(i > MAX-1)
{
while(!isspace(ch))
in_file.get(ch);
break;
}
ch = tolower(ch);
array[i] = ch;
i++;
in_file.get(ch);
}
for(int j = 0; j < i; j++)
cout << array[j];
cout << endl;
}
void build_list(ifstream& in_file, char array[])
{
Concordance c;
int count = 0;
while(!in_file.eof())
{
read_word(in_file, array);
c.insert(array, count);
}
cout << c;
}
最佳答案
char array[]
的类型是char *
,所以在查找匹配的函数时,没有找到。您可以通过使用 typedef char* Word;
并在需要它的函数中强制执行最大长度来解决此问题。
关于C++ 程序编译器错误 : No Matching Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18950158/
我正在尝试为匹配中的每个匹配呈现一些 HTML,但是,我不太确定 实际上是正确的。 更具体地说,我不确定我是否可以使用 v-bind:match='match'在与循环相同的元素上 v-for='ma
它具有看似简单的代码: method match(Any:U: |) { self.Str; nqp::getlexcaller('$/') = Nil } 但是,这是它的行为: (^3).matc
如果您想检查某项是否与正则表达式匹配,如果是,请打印第一组,您就可以了.. import re match = re.match("(\d+)g", "123g") if match is not N
以下两个查询的结果有差异吗? SELECT * FROM table1, table2 WHERE ( MATCH(table1.row1) AGAINST('searchstring' IN
我正在尝试为我的日志文件创建一个语法文件。它们采用以下格式: [time] LEVEL filepath:line - message 我的语法文件如下所示: :syn region logTime
String#match 和 Regexp#match 在匹配成功时返回一个 MatchData: "".match(//) # => # //.match("") # => # //.match(:
我的代码中有这个函数: func match(match: GKMatch, player playerID: String, didChangeState state: GKPlayerConnec
我对 match 和 case 之间的区别感到困惑。在 document ,其中提到match支持通用模式匹配。 > (define (m x) (match x [(list a
我在检查特定元素中的空 HTML 内容时遇到了问题。当我使用 someElement.trim().match("") 即使 HTML 内容为空,我有时也会得到 true。我改成了 someEleme
我正在尝试使用正则表达式查找包含特定词的两个词之间的所有内容,但是这些词是重复的,所以我没有得到我想要的匹配项。 例如,我想要“你好”和“再见”之间的所有内容,以便它们之间存在“苹果”一词: hell
我目前正在构建一个 PHP 脚本,它将在需要时响应 HTTP“304 Not Modified”。 (请参阅 question #2086712 了解我目前所做的事情)。 目前我回答以下问题: If-
给定以下 XML 10 我希望能够正确识别内部 的 s : result = subject.gsub(/]*>)/, '<') 解释: ]* # any number of charact
这个问题在这里已经有了答案: How to error handle 1004 Error with WorksheetFunction.VLookup? (3 个回答) 3年前关闭。 目标:查找输入
我已经尝试了好一阵子了,但是我似乎无法弄清楚这两者之间的区别。特别是,与数据数组有关的差异: PS C:>$myarray = "a", "ab", "abc" PS C:>$myarray -mat
我正在努力研究如何构建一个宏,让我可以将模式和结果以向量的形式传递给 core.match/match 。我希望能够做到这一点: (let [x {:a 1} patterns [[{:a
这个问题在这里已经有了答案: Reference - What does this regex mean? (1 个回答) 关闭 8 年前。 如果这看起来微不足道但只是为了理解正则表达式,请原谅我:
我的 MySQL 表中有大约 20 行,其 Title 列为 Elsewhere 并具有其他不同的列参数。 我目前正在使用这样的查询,因为我的大多数搜索(通过 PHP 文件)都需要我进行猜测。所以我使
当找到匹配时,我必须从字符串中删除单词 让我们看看 我的输入字符串是 “肯诺克斯路” 比赛表演中的单词表 街道 驾驶 道路 4. 车道 输出字符串应该是: KENOX 我正在使用 vb.net 作为此
我正在搜索以下形式的字符串模式: XXXAXXX # exactly 3 Xs, followed by a non-X, followed by 3Xs 所有的 X 必须是相同的字符,并且 A 不能
好吧,我是 gulp 和 sass 的新手,我正在努力让它发挥作用。我正确安装了所有东西,但我收到了这个愚蠢的错误。有解决办法吗? PS C:\Users\Bojan Kolano\Desktop\F
我是一名优秀的程序员,十分优秀!