Я получаю ошибки со следующим кодом и не знаю, где я ошибаюсь.Исходные синтаксические ошибки 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;
, где он говорит: «Определение функции не допускается до„{“знак. Вторая ошибка, я получаю на что есть ожидается, «}» в конце ввода, но независимо от того, сколько я положил в или оставить в это все еще дает такое же сообщение об ошибке.
и идеи ??
Вы не можете определить функцию внутри другой функции. Переместите объявления функции-члена за пределы основного. – stardust
'main' - это функция; у вас есть все ваши другие функции * внутри * 'main'. Функции не «гнездятся» на C++. –
Это повредит вам, ребята, когда новые встроенные функции будут введены в C++ 11. :) – Kiruse