Cant get the size of the array

Write your question here.

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
// vector::operator[]
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main ()
{       
		std::cout << "Give a person a name: " << endl;

		//string inputString;

		string inputString;		
		cin >> inputString;	

	    std::string s(inputString);
		std::vector<char> myVector( s.begin(), s.end() );

		for ( char c : myVector )
		{
			std::cout << c << endl;
		}

		for (int i= 0; i < myVector[i]; i++)
		{
			std::cout << i << "\n";
		}

		std::cout << "Enter the index of the letter you want to change: " << endl;

		int index;

		cin >> index;
		
		if(index > myVector.size())
		{
			std::cout << "index is outside the vector" << endl;
		}
		else
		{
			
		}

		std::cout << " Enter the characters you wish to print on index: " <<  endl;	

		std::cout << "The person is named:" << endl; 
			
  return 0;

}


The program goes this far and stops so I can´t cin a number in index

[code]
std::cout << "Enter the index of the letter you want to change: " << endl;

int index;

cin >> index;

if(index > myVector.size())
{
std::cout << "index is outside the vector" << endl;
}
else
{

}[code]

This coder doesnt run at all and I can´t see the problem.
Last edited on
morning,
change line 25 to
 
	for (int i = 0; i < myVector.size(); i++)
Why are you using 3 different variables (inputString, s and myVector) to hold the same data?

I think the problem is with the loop condition of the second loop: i < myVector[i]
Topic archived. No new replies allowed.