Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 10.10.2012, 15:54   #1
red6ds
 
Регистрация: 01.05.2012
Сообщений: 6
Вопрос что то не работает....

Я написал клас card но почему то МВС 2012 експрес не компилирует...

вот код


Код:
#ifndef CARD_H
#define CARD_H

#include <iostream>
using std::ostream;
using std::istream;

#include <string>
using std::string;
#include <map>
using std::map;
#include <vector>
using std::vector;


class Card {
friend ostream &operator<<(ostream &, const Card &);
friend istream &operator>>(istream &, Card &);
 


public:
  Card( string = "spade", string = "A" );
  Card &setCard(string, string);
  string getSuit() const;
  string getRank() const;
  int getPoints() const;
private:
  static const vector<string> vr ;
  static const vector<string> vs ;
  static const map<string, int> rtp;
  string Suit;
  string Rank;
  int Points;

};

  
#endif







#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include "card.h"


  static const vector<string> vr {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};   //vaild ranks
  static const vector<string> vs {"spade", "heart", "diamond", "club"};   //vaild suits
  static const map<string, int> rtp {{"2", 2}, {"3", 3}, {"4", 4}, {"5", 5}, {"6", 6}, {"7", 7}, {"8", 8}, {"9", 9}, {"10", 10}, {"J", 10}, {"Q", 10}, {"K", 10}, {"A", 11}}; //rank to points

Card::Card(string S, string R)
  {
    setCard(S, R);
    Points = rtp[Rank];
  } 
Card &Card::setCard(string S, string R)
  {
    std::vector<int>::iterator fit;  //a iterator for find
    fit = std::find(vs.begin(), vs.end(), S);
    if(fit != vs.end())
        Suit = S;
    else
      {
        Suit = "Spade";
        std::cout<<"The entered [Suit]character(s) are not allowed"<<std::endl;
        std::cout<<"The Cards Suit is "<<Suit<<std::endl;
      }
    fit = std::find(vr.begin(), vr.end(), R);
    if(fit != vr.end())
        Rank = R;
    else
      {
        Rank = "A";
        std::cout<<"The entered [Rank]character(s) are not allowed"<<std::endl;
        std::cout<<"The Cards Rank is "<<Rank<<std::endl;
      }	
    return *this;	 
  }
  
string Card::getSuit() const
  {
    return Suit;
  }
string Card::getRank() const
  {
    return Rank;
  }
int Card::getPoints() const
  {
    return Points;
  }
ostream &operator<<(ostream &output, const Card &c)
  {
output<<"["<<c.getSuit()<<" "<<c.getRank()<<"]";
return output;

  }

istream &operator>>(istream &input, Card &c)
  {
    char temp1[50]; //buffer1 [Suit]
    char temp2[50]; //buffer2 [Rank]
    input >> std::setw(50) >>temp1;
    input >> std::setw(50) >>temp1;
    c.setCard(temp1, temp2);
    return input;

  }
эрор в этих строках

static const vector<string> vr {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}; //vaild ranks
static const vector<string> vs {"spade", "heart", "diamond", "club"}; //vaild suits
static const map<string, int> rtp {{"2", 2}, {"3", 3}, {"4", 4}, {"5", 5}, {"6", 6}, {"7", 7}, {"8", 8}, {"9", 9}, {"10", 10}, {"J", 10}, {"Q", 10}, {"K", 10}, {"A", 11}}; //rank to points


заране спс

Последний раз редактировалось Stilet; 10.10.2012 в 16:18.
red6ds вне форума Ответить с цитированием
Старый 10.10.2012, 16:41   #2
Granus
С++
Форумчанин
 
Аватар для Granus
 
Регистрация: 22.09.2008
Сообщений: 791
По умолчанию

синтаксис определения статических членов другой
Код:
const vector<string> Card::vr {...};
Форматируйте код, будьте людьми.
Granus вне форума Ответить с цитированием
Старый 10.10.2012, 19:07   #3
red6ds
 
Регистрация: 01.05.2012
Сообщений: 6
По умолчанию

вроде в c++11 так можно... если нет то не скажите как???
red6ds вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
программа не работает, что не так? klubnika Общие вопросы C/C++ 7 11.10.2011 22:47
Что то не работает как надо... rezak91 Паскаль, Turbo Pascal, PascalABC.NET 9 24.05.2010 22:27
Не работает программа, что делать? St1mkA Помощь студентам 6 28.04.2010 20:22
Работа с TXT, что то не работает nolz Помощь студентам 6 12.10.2009 21:33
не работает, что-то не так. Анжелика Помощь студентам 2 06.12.2008 21:47