Conversion error message

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.

It happens on line 121:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* 
 * 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:  
 */

using namespace 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.
Last edited on
You probably want to use indices directly:
1
2
3
4
5
for (size_t i = 0; i != suits.length(); ++i) {
 for (size_t j = 0; j != ranks.length(); ++j) {
  Card c=createCard(suits[i], ranks[j]);
 }
}


or use iterators:
1
2
3
4
5
for (string::iterator *s = suits.begin(); s != suits.end(); ++s) {
 for (string::iterator *r = ranks.begin(); r != ranks.end(); ++r) {
  Card c=createCard(*s, *r);
 }
}

Last edited on
Topic archived. No new replies allowed.