- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在开发一个翻译/音译程序,该程序读取一个英文故事,然后使用英文/ Sprite 语词典将其翻译成 Sprite 语。在下面显示的代码之后,我解释了我收到的错误。
我有很多代码,我不确定是否应该全部发布,但我会发布我认为应该足够的代码。如果我的代码看起来很奇怪,我深表歉意 - 但我只是一个初学者。
有一个main文件,一个包含两个类的header文件:Translator和Dictionary,以及一个cpp文件来实现类的功能。
我有一个构造函数,可以将字典文件读入dictFileName并将英文单词复制到englishWord,将 Sprite 词复制到elvishWord :
Translator::Translator(const char dictFileName[]) : dict(dictFileName)
{
char englishWord[2000][50];
char temp_eng_word[50];
char temp_elv_word[50];
char elvishWord[2000][50];
int num_entries;
fstream str;
str.open(dictFileName, ios::in);
int i;
while (!str.fail())
{
for (i=0; i< 2000; i++)
{
str>> temp_eng_word;
str>> temp_elv_word;
strcpy(englishWord[i],temp_eng_word);
strcpy(elvishWord[i],temp_elv_word);
}
num_entries = i;
}
str.close();
}
在主文件中,英文行被读入 toElvish 函数,并标记为单词数组 temp_eng_words。
在这个 toElvish 函数中,我正在调用另一个函数;翻译,它读入 temp_eng_words 并且应该返回 Sprite 词:
char Translator::toElvish(char elvish_line[],const char english_line[])
{
int j=0;
char temp_eng_words[2000][50];
//char temp_elv_words[2000][50]; NOT SURE IF I NEED THIS
std::string str = english_line;
std::istringstream stm(str);
string word;
while( stm >> word) // read white-space delimited tokens one by one
{
int k=0;
strcpy (temp_eng_words[k],word.c_str());
k++;
}
for (int i=0; i<2000;i++) // ERROR: out_s was not declared in this scope
{
Dictionary::translate (out_s,temp_eng_words[i]); // ERROR RELATES TO THIS LINE
}
}
这是翻译函数:
char Dictionary::translate (char out_s[], const char s[])
{
int i;
for (i=0;i < numEntries; i++)
{
if (strcmp(englishWord[i], s)==0)
break;
}
if (i<numEntries)
strcpy(out_s,elvishWord[i]);
}
我的问题是,当我运行该程序时,出现错误“*out_s 未在此范围内声明*”。
如果您已经阅读了所有这些内容,谢谢;任何建议/线索将不胜感激。 :)
最佳答案
正如您在下面的代码中看到的,您在函数中使用了 out_s,但尚未在函数中声明它。您可以在函数中使用全局变量或局部变量。我建议你阅读 this
char Translator::toElvish(char elvish_line[],const char english_line[]) {
int j=0;
char temp_eng_words[2000][50];
//char temp_elv_words[2000][50]; NOT SURE IF I NEED THIS
std::string str = english_line;
std::istringstream stm(str);
string word;
while( stm >> word) // read white-space delimited tokens one by one
{
int k=0;
strcpy (temp_eng_words[k],word.c_str());
k++;
}
for (int i=0; i<2000;i++) // ERROR: out_s was not declared in this scope
{
Dictionary::translate (out_s,temp_eng_words[i]); // ERROR RELATES TO THIS LINE
}}
关于c++ - 翻译/音译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16449506/
有没有办法让音译在 Emacs 中工作,就像现在在 Gmail 中一样?我特别有兴趣让它在西里尔文中工作。 作为引用,Gmail 执行以下操作:我可以输入svoboda,它会输出свобода。这允许
ruby中非英文字符的音译最简单的方法是什么。即转换如: 翻译“Gévry” #=> "Gevry" 最佳答案 Ruby 有一个 Iconv其 stdlib 中的库以与通常的 iconv 命令非常相似
ruby 1.9.3 警告 iconv 弃用,但我使用 iconv 删除变音符号以从 Iconv.iconv('asccii//translit', 'utf-8', 'Těžiště') 返回 Te
在 Ruby on Rails 中,您可以轻松地将“任何”文本转换为适用于子域/路径名的格式。 1) "I am nobody." -> "i-am-nobody" 2) "Grünkohl is a
我想将西里尔文字符串音译成最接近的拉丁文等价物。例如。 “матрешка”=> “matreshka”,“водка”=> “伏特加”。所以理想情况下,我希望在 NSString 或其他已经了解字母
以下是将 Google Transliteration 代码集成到 ASP.Net Pages 中的示例代码(随处可用)。 但我的问题是,如何在将在运行时生成的文本框中启用音译?此脚本需要文本框的 I
我正在使用 Java Swing 开发一个音译项目。它可以访问互联网,但我无法设置它。我们该怎么做?我们需要下载 Google API 库还是只需要一个函数调用就可以了? 这里有一些有用的音译链接:
在我们的 RoR 项目中,我们使用 postgres unaccent 函数来检索我们模型名称属性之一的非重音版本。 name 属性可以包含来自各种语言的任何重音字符。然后我们将其保存为 unacce
如何在我的 Java 应用程序中使用 Google Transliteration API。 如果我给一个String(英语或阿拉伯语)作为输入,Google Transliterator API 应
我正在做一个基于泰米尔语的 Web 应用程序。在我的应用程序中,我使用动态字段来添加用户详细信息。那么,动态字段有多个 ID 如何做到这一点或如何使用基于类的 Google 音译? // Lo
我有一个字符串对象 “有多个字符甚至特殊字符” 我正在尝试使用 UTF8Encoding utf8 = new UTF8Encoding(); ASCIIEncoding ascii = new AS
我使用过“Google AJAX Transliteration API”,它对我来说很顺利。 http://code.google.com/apis/ajaxlanguage/documentati
我是一名优秀的程序员,十分优秀!