no suitable conversion function from "std::basic_string <char, std::char_traits<char>,std::allocator<char>>"to "int" exists

My code is unfinished at the moment but the problem I'm having is the "name" of if(isspace(name[j].substr(i, 0} is giving me the error no suitable conversion function from "std::basic_string <char, std::char_traits<char>,std::allocator<char>>"to "int" exists

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
#include <iostream>
#include <ctype.h>
#include <string>
#include <vector>
#include <array>

using namespace std;

void alphabetical(vector <string> name, vector <string> address, vector <string> state);
void city(vector <string> name, vector <string> address, vector <string> state);
void zip(vector <string> name, vector <string> address, vector <string> state);

int main()
{
	system("CLS");

	vector <string> name(12);
	vector <string> address(12);
	vector <string> state(12);

	name[0] = "Chevy Chase";		address[0] = "17492 Camino De Yatasto";	state[0] = "Pacific Palisades, CA 90272";
	name[1] = "Clint Eastwood";		address[1] = "846 Stradella Rd.";		state[1] = "San Diego, CA 92101";
	name[2] = "Dan Ayckroyd";		address[2] = "7708 Woodrow Wilson Dr.";	state[2] = "Hollywood, CA 90027";
	name[3] = "Tom Hanks";			address[3] = "23414 Malibu Colony Rd.";	state[3] = "Malibu, CA 90263";
	name[4] = "Michael Keaton";		address[4] = "826 Napoli Dr.";			state[4] = "Pacific Palisades, CA 90272";
	name[5] = "Antonio Banderas";	address[5] = "201 S. Rockingham Ave.";	state[5] = "Brentwood, CA 94513";
	name[6] = "Jay Leno";			address[6] = "1151 Tower Rd.";			state[6] = "Beverly Hills, CA 90209";
	name[7] = "Jerry Seinfield";	address[7] = "1222 N. Kings Rd.";		state[7] = "West Hollywood, CA 90038";
	name[8] = "Harrison Ford.";		address[8] = "655 McCulloch Dr.";		state[8] = "Brentwood, Ca 94513";
	name[9] = "John Travolta";		address[9] = "4810 Woodley Ave.";		state[9] = "Encino, CA 91316";
	name[10] = "Tom Cruise";		address[10] = "1525 Sorrento Dr.";		state[10] = "Pacific Palisades, CA 90272";
	name[11] = "Denzel Washington";	address[11] = "4701 Sancola Ave.";		state[11] = "Hollywood, CA 90027";

	int i=0, choice=0;

	while(i != 1)
	{
		cout << "Hello, I am the celebrity database. There are three options:\n1.) Sort the celebrities alphabetically by last name\n2.) List the celebrities by the name of the city that they reside in\n3.) List the celebrities that reside in a zipcode";
		cout << "\nWhich option would you like?(1, 2, or 3)  ";
		cin >> choice;

		switch(choice)
		{
			case(1):
			{
				alphabetical(name, address, state);
				break;
			}
			case(2):
			{	
				city(name, address, state);
				break;
			}
			case(3):
			{
				zip(name, address, state);
				break;
			}
			default:
			{
				cout << "Sorry, but that wasn't an option";
				break;
			}
		
		}
	
		cout << "If you would like to try a different option press 0, otherwise press 1";
		cin >> i;
	}

	cout << "Thank you for using the celebrity database";





	
	
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}

void alphabetical(vector<string> name, vector<string> address, vector<string> state)
{
	int i, j;
	vector <int> order{ 12 };
	for(j = 0; j <= 11 ;j++ )
		for (i = 0 ;i <= name[j].length(); i++)
		{
			if (isspace(name[j].substr(i, 0)))
				order[j] = i;
		}
}

void city(vector<string> name, vector<string> address, vector<string> state)
{

}

void zip(vector<string> name, vector<string> address, vector<string> state)
{

}
A substring is still a string, and that's not what is expected by isspace().

Replace name[j].substr(i,0) by name[j][i] on line 101 if you want a single char.

No idea what you are trying to do in that routine, though.
Last edited on
"std::basic_string <char, std::char_traits<char>,std::allocator<char>>" is just the templately "behind the curtain" type that a string really is.

So the error is actually: Cannot convert string to int.

As lastchance said, you want name[j][i] most likely. Note that the substr(i, 0) call doesn't make sense anyway, because you are saying the length of the substring is 0, which can only be an empty string.
Last edited on
Also note that passing vector<> by value (as here) causes an extra copy of the whole vector. Pass by const ref if not changed, or by ref if changed.
Topic archived. No new replies allowed.