When I compile my program I am getting this error message: error: conversion from gnu_cxx::_normal_iterator<char*, std::basic_string<char, std:: char_traits<char>, std::allocator<char> > > to non-scalar type std::string requested.
/*
* Written By: Kenneth Houser
* Date: 04/28/2010
* Algorithm:
#+Warcard.gen
#+Warhand.gen
Let create Deck () name
Function {
Let deck name <>
Generate each (suit) from < 'H' 'D' 'C' 'S' >
[+]
Generate each(rank) from < 'A' 'K' 'Q' 'J' '10' '9' '8' '7' '6' '5' '4' '3' '2' >
[+] {
Let c name create Card (rank, suit)
Append c onto deck
}
Return deck
}
Let size(deck) name
Function {
Generate each(c) from deck
[+] @f: Let count name 0
@i: Let count name count + 1
Return count
}
Let Shuffle(alias deck) name
Procedure {
Generate each(n) from 1 to 100
[+] {
Let m name random() % 52 + 1
Let n name random() % 52 + 1
Let c1 name deck[m]
Let c2 name deck[n]
Let deck[m] name c2
Let deck[n] name c1
}
}
Let Get (alias card) from (deck) name
Procedure {
Select
size(deck) > 0 -> {
Let card name deck[1]
Delete deck[1]
}
otherwise -> {
Print "I think Candlejack stol-"
Stop
}
}
Let Discard (alias card) from (hand) name
Procedure {
Select
size(hand) > 0 -> {
Let card name hand[1]
Delete hand[1]
}
otherwise -> {
Print "Those pesky gnomes stole your cards!"
Stop
}
}
Let Place (alias card) on bottom of (hand1) from (hand2) name
Procedure {
Generate each(c) from hand2
[+] @i: {
Discard (card) from (hand2)
Add (card) to (hand1)
}
}
*
* Last Update:
*/
usingnamespace std;
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include "Warcard.cc"
#include "Warhand.cc"
typedef vector <Card> Deck;
template <class T>
void append(T t, vector<T> &v) {
v.push_back(t);
}
Deck createDeck() {
Deck deck;
ifstream Suitfile;
ifstream Rankfile;
Suitfile.open("Suit.dat");
Rankfile.open("Rank.dat");
string suits;
string ranks;
while (!Suitfile.eof()) {
suits.push_back(Suitfile.get());
}
while (!Rankfile.eof()) {
ranks.push_back(Rankfile.get());
}
string::iterator *s;
string::iterator *r;
for (int n=0; n < suits.length(); n++) { //for(s=suits; s<str.size(); s++)
for (int n=0; n < ranks.length(); n++) { //for(r=ranks; s<str.size(); r++)
Card c=createCard((*r),(*s));
deck.push_back(c);
}
}
return deck;
}
int sizeD(Deck deck) {
return deck.size();
}
#include <stdlib.h>
#include <sys/time.h>
void setuprand() {
struct timeval tv; struct timezone tz;
gettimeofday(&tv, &tz);
srand(tv.tv_usec);
}
int random(int m, int n) {
int ans=m+((n-m+1) * (rand()/(RAND_MAX+1.0)));
return ans;
}
void shuffle(Deck &deck) {
setuprand();
int n;
Card c1, c2;
for (n=0; n<100; n=n+1) {
int a,b;
a=random(0,deck.size()-1);
b=random(0,deck.size()-1);
c1=deck[a];
c2=deck[b];
deck[b]=c1;
deck[a]=c2;
}
}
void get (Card &card, Deck &deck) {
card=deck[0];
deck.erase(deck.begin());
}
void testDeck() {
Deck deck;
deck=createDeck();
cout << "Done creating deck." << endl;
int n;
Card card;
for (n=0; n<5; n++) {
get(card,deck);
cout << "Card" << ' ' << n << " -- " << getFormat(card) << endl;
}
cout << "Deck now has " << sizeD(deck) << "cards." << endl;
shuffle(deck);
cout << "Finished shuffling deck." << endl;
cout << "The deck size is " << sizeD(deck) << " now." << endl;
}
#ifdef DECKTEST
int main () {
testDeck();
return 0;
}
#endif
I am adding two data files to strings then with two for loops I want the iterators s and r to move down the strings suits and ranks, and with the createCard to make a "card" and append it onto deck. I am stumped as to what the error message means.