首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >翻译/音译问题

翻译/音译问题
EN

Stack Overflow用户
提问于 2013-05-08 20:21:25
回答 1查看 635关注 0票数 2

我正在做一个翻译/音译程序,它读一个英语故事,然后用英语/精灵词典把它翻译成精灵。在下面显示的代码之后,我将解释我收到的错误。

我有很多代码,我不确定是否应该全部发布,但是我会发布我认为应该足够的内容。很抱歉,如果我的代码看起来很奇怪--但我只是个初学者。

有一个文件,一个包含两个类的文件:TranslatorDictionary,以及一个cpp文件来实现类函数。

我有一个构造函数,它将字典文件读入dictFileName,并将英文单词复制到englishWord,中,将elvish单词复制到elvishWord中。

代码语言:javascript
复制
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函数中,并被标记为一个单词数组,名为toElvish

在这个temp_eng_words函数中,我调用了另一个函数: toElvish,它用toElvish读取并返回精灵词:

代码语言:javascript
复制
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
    }

}

这是转换函数:

代码语言:javascript
复制
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没有在这个范围内声明*‘。

如果您已经阅读了所有这些,谢谢;任何建议/线索都将不胜感激。:)

EN

回答 1

Stack Overflow用户

发布于 2019-07-21 10:12:28

正如您在下面的代码中所看到的,您在函数中使用了out_s,但是您没有在函数中声明它。可以在函数中使用全局变量或局部变量。我建议你读

代码语言:javascript
复制
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
}}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16449506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档