标题:求高手解决C++中的 cin cout 为什么重视报错
取消只看楼主
阳光猪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-3-5
结帖率:100%
已结贴  问题点数:20 回复次数:6 
求高手解决C++中的 cin cout 为什么重视报错
#include "VEmotion.h"
#include<iostream>
using namespace std;
void main()
{
 int index=0;
 AMsg pMsg;
 AMsg UName;
AMsg questions[10]={"你喜欢跳舞吗玩吗?(y/n)","我想和你交朋友,你愿意吗?(y/n)","亲爱的,你爱我吗?(y/n)","嫁给我吧(y/n)","我们离婚吧(y/n)"}
};
cout<<"输入姓名:";
cin>>UName;
cout<<"今天遇到一个熟悉的陌生人,他对你很感兴趣……"<<endl;
VEmotion sample;
cout<<"嗨!"<<UName<<",";
 while(1)
 {
  cout<<questions[index];
  cin>>pMsg;
  sample.event(pMsg);
  index=sample.getRelation()-1;
  if(sample.Rejection()==MAX_BEAR_TIME)
  {
    cout<<endl<<"***你很讨厌我吗???****"<<endl;
  }
  if(sample.Relation()==BYEBYE)
  {
    cout<<endl<<"***对不起,不要流泪****"<<endl;
  }
 }
}

--------------------Configuration: zhu3_5 - Win32 Debug--------------------
Compiling...
main.cpp
C:\Documents and Settings\zhu3_5\main.cpp(10) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\zhu3_5\main.cpp(11) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\zhu3_5\main.cpp(11) : error C2501: 'cout' : missing storage-class or type specifiers
C:\Documents and Settings\zhu3_5\main.cpp(11) : error C2371: 'cout' : redefinition; different basic types
        c:\program files\microsoft visual studio\vc98\include\ostream.h(139) : see declaration of 'cout'
C:\Documents and Settings\zhu3_5\main.cpp(11) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\zhu3_5\main.cpp(12) : error C2143: syntax error : missing ';' before '>>'
C:\Documents and Settings\zhu3_5\main.cpp(12) : error C2501: 'cin' : missing storage-class or type specifiers
C:\Documents and Settings\zhu3_5\main.cpp(12) : error C2371: 'cin' : redefinition; different basic types
        c:\program files\microsoft visual studio\vc98\include\istream.h(173) : see declaration of 'cin'
C:\Documents and Settings\zhu3_5\main.cpp(12) : error C2143: syntax error : missing ';' before '>>'
C:\Documents and Settings\zhu3_5\main.cpp(13) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\zhu3_5\main.cpp(13) : error C2501: 'cout' : missing storage-class or type specifiers
C:\Documents and Settings\zhu3_5\main.cpp(13) : error C2371: 'cout' : redefinition; different basic types
        c:\program files\microsoft visual studio\vc98\include\ostream.h(139) : see declaration of 'cout'
C:\Documents and Settings\zhu3_5\main.cpp(13) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\zhu3_5\main.cpp(15) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\zhu3_5\main.cpp(15) : error C2501: 'cout' : missing storage-class or type specifiers
C:\Documents and Settings\zhu3_5\main.cpp(15) : error C2371: 'cout' : redefinition; different basic types
        c:\program files\microsoft visual studio\vc98\include\ostream.h(139) : see declaration of 'cout'
C:\Documents and Settings\zhu3_5\main.cpp(15) : error C2143: syntax error : missing ';' before '<<'
C:\Documents and Settings\zhu3_5\main.cpp(16) : error C2143: syntax error : missing ';' before 'while'
C:\Documents and Settings\zhu3_5\main.cpp(17) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\zhu3_5\main.cpp(17) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\zhu3_5\main.cpp(31) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\zhu3_5\main.cpp(31) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\zhu3_5\main.cpp(31) : error C2143: syntax error : missing ';' before '}'
搜索更多相关主题的帖子: include 陌生人 交朋友 我们离婚吧 爱我 
2014-03-05 22:29
阳光猪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-3-5
得分:0 
谢谢大家,粘贴上去才看到数组的地方多了一个花括号 可是cin cout的问题还在呀

#include "VEmotion.h"
#include<iostream>
using namespace std;
void main()
{
 int index=0;
 AMsg pMsg;
 AMsg UName;
AMsg questions[10]={"你喜欢跳舞吗玩吗?(y/n)","我想和你交朋友,你愿意吗?(y/n)","亲爱的,你爱我吗?(y/n)","嫁给我吧(y/n)","我们离婚吧(y/n)"};
cout<<"输入姓名:";
cin>>UName;
cout<<"今天遇到一个熟悉的陌生人,他对你很感兴趣……"<<endl;
VEmotion sample;
cout<<"嗨!"<<UName<<",";
 while(1)
 {
  cout<<questions[index];
  cin>>pMsg;
  sample.event(pMsg);
  index=sample.getRelation()-1;
  if(sample.getRejection()==MAX_BEAR_TIME)
  {
    cout<<endl<<"***你很讨厌我吗???****"<<endl;
  }
  if(sample.getRelation()==BYEBYE)
  {
    cout<<endl<<"***对不起,不要流泪****"<<endl;
  }
 }
}
--------------------Configuration: zhu3_5 - Win32 Debug--------------------
Compiling...
main.cpp
C:\Documents and Settings\zhu3_5\main.cpp(10) : error C2872: 'cout' : ambiguous symbol
C:\Documents and Settings\zhu3_5\main.cpp(11) : error C2872: 'cin' : ambiguous symbol
C:\Documents and Settings\zhu3_5\main.cpp(12) : error C2872: 'cout' : ambiguous symbol
C:\Documents and Settings\zhu3_5\main.cpp(14) : error C2872: 'cout' : ambiguous symbol
C:\Documents and Settings\zhu3_5\main.cpp(17) : error C2872: 'cout' : ambiguous symbol
C:\Documents and Settings\zhu3_5\main.cpp(18) : error C2872: 'cin' : ambiguous symbol
C:\Documents and Settings\zhu3_5\main.cpp(23) : error C2872: 'cout' : ambiguous symbol
C:\Documents and Settings\zhu3_5\main.cpp(27) : error C2872: 'cout' : ambiguous symbol
Error executing cl.exe.

main.obj - 8 error(s), 0 warning(s)
2014-03-06 16:38
阳光猪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-3-5
得分:0 
回复 2楼 wp231957
谢谢
2014-03-06 16:39
阳光猪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-3-5
得分:0 
回复 3楼 梦落尘埃
非常感谢
2014-03-06 16:40
阳光猪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-3-5
得分:0 
回复 4楼 peach5460
感谢
2014-03-06 16:40
阳光猪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-3-5
得分:0 
#if !defined _VEmotion
#define _VEmotion
#endif
#include <iostream.h>
#include<string.h>
#define MSG_LEN_MAX 100
#define MAX_BEAR_TIME 3
typedef char AMsg[MSG_LEN_MAX];
enum AState{
   STRANGER=1,
   KNOWN=2,
   FRIEND=3,
   COUPLE=5,
   BYEBYE=0,
};

class VEmotion  
{
public:
    VEmotion();
    virtual ~VEmotion();
    int event(AMsg pMsg);
    AState getRelation()
    {
      return Relation;
    }
    int getRejection()
    {
      return Rejection;
    }
private:
     AState  Relation;
     int  Rejection;


};
2014-03-06 17:22
阳光猪
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2014-3-5
得分:0 
VEmotion.cpp文件



#include "VEmotion.h"

VEmotion::VEmotion()
{
  Relation=STRINGER;
  Rejection=0;
  cout<<"========================================"<<endl;
  cout<<"==========|欢迎来到虚拟感情世界|========"<<endl;
  cout<<"========================================"<<endl<<endl;
}
int VEmotion::event(AMsg pMsg)
{
  switch(Relation)
  {
    case STRINGER;
        if(strcmp(pMsg,"Y")==0||strcmp(pMsg,"y")==0)
        {
          cout<<endl<<"***彼此熟悉了。***"<<endl<<endl;
          Relation=KNOWN;
        }
        else if(strcmp(pMsg,"N")==0||strcmp(pMsg,"n")==0)
            Rejetion++;
        else
        {
          strcpy(pMsg,"Y");
          event(pMsg);
        }
        break;
        case KNOWN;
             if(strcmp(pMsg,"Y")==0||strcmp(pMsg,"y")==0)
        {
          cout<<endl<<"***我们成为朋友了。***"<<endl<<endl;
          Relation=FRIEND;
        }
        else if(strcmp(pMsg,"N")==0||strcmp(pMsg,"n")==0)
            Rejetion++;
        else
        {
          strcpy(pMsg,"Y");
          event(pMsg);
        }
        break;
        case FRIEND
                if(strcmp(pMsg,"Y")==0||strcmp(pMsg,"y")==0)
        {
          cout<<endl<<"***我们相爱了。***"<<endl<<endl;
          Relation=LOVER;
        }
        else if(strcmp(pMsg,"N")==0||strcmp(pMsg,"n")==0)
            Rejetion++;
        else
        {
          strcpy(pMsg,"Y");
          event(pMsg);
        }
        break;
        case LOVER
                if(strcmp(pMsg,"Y")==0||strcmp(pMsg,"y")==0)
        {
          cout<<endl<<"***我们结婚了。***"<<endl<<endl;
          Relation=COUPLE;
        }
        else if(strcmp(pMsg,"N")==0||strcmp(pMsg,"n")==0)
            Rejetion++;
        else
        {
          strcpy(pMsg,"Y");
          event(pMsg);
        }
        break;
        case CUOPLE
                if(strcmp(pMsg,"Y")==0||strcmp(pMsg,"y")==0)
        {
          cout<<endl<<"***离婚吧。***"<<endl<<endl;
          Relation=BYEBYE;
        }
        else if(strcmp(pMsg,"N")==0||strcmp(pMsg,"n")==0)
        {
           cout<<endl<<"***不答应离婚,依然生活在一起***"<<endl<<endl;
        }
        else
        {
          strcpy(pMsg,"Y");
          event(pMsg);
        }
        break;
  }
  return 0;

}
VEmotion::~VEmotion()
{

}
2014-03-06 17:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-428074-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045586 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved