определение — основные синтаксические ошибки C ++

Я получаю ошибки с помощью следующего кода и не знаю, где я иду не так.

#include <iostream>
#include <fstream>
#include <cstring>
#include "Translator.h"
using namespace std;

int main (void)

{

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]);
}

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
}

}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();

}
}}

Первая ошибка, которую я получаю —

char Dictionary::translate (char out_s[], const char s[])
{
int i;

где он говорит: «Определение функции не допускается до токена« {». Вторая ошибка, которую я получаю, заключается в том, что в конце ввода есть ожидаемое«} », но независимо от того, сколько я вставляю или пропускаю это все еще дает то же самое сообщение об ошибке.

А идеи ??

-1

Решение

Вы определяете все функции внутри main(), Переместить их все раньше main(),

4

Другие решения

Вы не должны определять функцию прямо в другой функции.
Определения функций идут после друг друга.

4

Не разрешается объявлять внутренние функции в C++,
Переместите свои функции в отдельную область, не вкладываясь в main,

4
По вопросам рекламы ammmcru@yandex.ru
Adblock
detector