c++ - Initializer but incomplete type? -


the following code gives me 2 errors when compile

#include <iostream> #include <fstream> #include <cstring> #include "translator.h"  using namespace std;  void dictionary::translate(char out_s[], const char s[]) {     int i;     char englishword[max_num_words][max_word_len];      (i=0;i < numentries; i++)     {        if (strcmp(englishword[i], s)==0)            break;     }      if (i<numentries)        strcpy(out_s,elvishword[i]); }  char translator::toelvish(const 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 need      std::string str = english_line;     std:: istringstream stm(str);     string word;     while( stm >> word) // read white-space delimited tokens 1 one     {         int k=0;         strcpy (temp_eng_words[k],word.c_str());         k++;      }       (int i=0; i<2000;i++) // error: out_s not declared in scope      {        dictionary::translate (out_s,temp_eng_words[i]); // error relates 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())     {       (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();     } }  

the first 1 @ std::string istringstream stm(str); says variable has initializer incomplete type. if put in std::string istringstream stm(str); says expected initializer before stm andstm not declared in scope.

it says out_s not declared in scope @ dictionary::translate (out_s,temp_eng_words[i]);. don't see why 1 parameter recognisied , 1 not?

thanks in advance.

you have include header file:

#include <sstream> #include <string> 

when want use stringstream , string.

meanwhile:

dictionary::translate (out_s,temp_eng_words[i]); 

if out_s not member of class, seems forgot define out_s before using inside toelvish.

meanwhile:

 while( stm >> word) // read white-space delimited tokens 1 one  {     int k=0; //^^why initialize k everytime read word?     strcpy (temp_eng_words[k],word.c_str());     k++;  } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -