读书人

定义类的时候老是提醒小弟我缺少分号

发布时间: 2012-08-02 11:35:26 作者: rapoo

定义类的时候老是提醒我缺少分号,感觉没缺少啊
*******************************************word.h**************************************************
#include <string>

struct Word{
string word;
string meanning;
string number;
string frequency;
Word(string,string,string,string);
Word();
};
*****************************************word.cpp******************************************************
#include"Word.h"

Word::Word(string wo,string me,string num,string freq){
word=wo;
meanning=me;
number=num;
frequency=freq;
}

Word::Word(){

}
******************************************main.cpp*******************************************************
#include<list>
#include<string>
#include<fstream>
#include<iostream>
#include"Word.h"
using namespace std;

void main(){
list<Word> WordList;
ifstream inf;
string line;
string tword;
string tmean;
string tnum;
string tfreq;
inf.open("cert4.txt");
if(!inf){
cout<<"FAIL!"<<endl;
exit(1);
}
while(getline(inf,line)){
int i;
Word tword;
string str;
int end;
end=line.find(",");
str=line.substr(0,end-1);





}



}
编译之后......

--------------------Configuration: WordList - Win32 Debug--------------------
Compiling...
main.cpp
c:\users\thunder\desktop\workspace\wordlist\word.h(4) : error C2146: syntax error : missing ';' before identifier 'word'
c:\users\thunder\desktop\workspace\wordlist\word.h(4) : error C2501: 'string' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(4) : error C2501: 'word' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(5) : error C2146: syntax error : missing ';' before identifier 'meanning'
c:\users\thunder\desktop\workspace\wordlist\word.h(5) : error C2501: 'string' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(5) : error C2501: 'meanning' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(6) : error C2146: syntax error : missing ';' before identifier 'number'
c:\users\thunder\desktop\workspace\wordlist\word.h(6) : error C2501: 'string' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(6) : error C2501: 'number' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(7) : error C2146: syntax error : missing ';' before identifier 'frequency'
c:\users\thunder\desktop\workspace\wordlist\word.h(7) : error C2501: 'string' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(7) : error C2501: 'frequency' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(8) : error C2629: unexpected 'struct Word ('
c:\users\thunder\desktop\workspace\wordlist\word.h(8) : error C2238: unexpected token(s) preceding ';'
Word.cpp
c:\users\thunder\desktop\workspace\wordlist\word.h(4) : error C2146: syntax error : missing ';' before identifier 'word'
c:\users\thunder\desktop\workspace\wordlist\word.h(4) : error C2501: 'string' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(4) : error C2501: 'word' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(5) : error C2146: syntax error : missing ';' before identifier 'meanning'
c:\users\thunder\desktop\workspace\wordlist\word.h(5) : error C2501: 'string' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(5) : error C2501: 'meanning' : missing storage-class or type specifiers


c:\users\thunder\desktop\workspace\wordlist\word.h(6) : error C2146: syntax error : missing ';' before identifier 'number'
c:\users\thunder\desktop\workspace\wordlist\word.h(6) : error C2501: 'string' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(6) : error C2501: 'number' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(7) : error C2146: syntax error : missing ';' before identifier 'frequency'
c:\users\thunder\desktop\workspace\wordlist\word.h(7) : error C2501: 'string' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(7) : error C2501: 'frequency' : missing storage-class or type specifiers
c:\users\thunder\desktop\workspace\wordlist\word.h(8) : error C2629: unexpected 'struct Word ('
c:\users\thunder\desktop\workspace\wordlist\word.h(8) : error C2238: unexpected token(s) preceding ';'
C:\Users\Thunder\Desktop\workspace\WordList\Word.cpp(3) : error C2065: 'string' : undeclared identifier
C:\Users\Thunder\Desktop\workspace\WordList\Word.cpp(3) : error C2146: syntax error : missing ')' before identifier 'wo'
C:\Users\Thunder\Desktop\workspace\WordList\Word.cpp(3) : error C2350: 'Word::Word::Word' is not a static member
C:\Users\Thunder\Desktop\workspace\WordList\Word.cpp(3) : error C2059: syntax error : ')'
C:\Users\Thunder\Desktop\workspace\WordList\Word.cpp(3) : error C2143: syntax error : missing ';' before '{'
C:\Users\Thunder\Desktop\workspace\WordList\Word.cpp(3) : error C2447: missing function header (old-style formal list?)
执行 cl.exe 时出错.

WordList.exe - 1 error(s), 0 warning(s)


[解决办法]
你老师可以休息了……

word.h

#include <string>
using namespace std;

谢谢

读书人网 >C++

热点推荐