Need help finding problem with code!

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
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string input = "";
	string ex = "";
	string result = "";

	cout << "Input a phase: ";
	cin >> input;

	for (int i = 0; i < input.length(); i++)
	{
	string ex = input.substr(i, 1);

	if ( ex == "A" || ex == "E" || ex == "I" || ex == "O" || ex == "U" || ex == "a" || ex == "e" || ex == "i" || ex == "o" || ex == "u")
	{
		cout << "_";
	}
	else
	{
		result = input.substr(i, 1);
		cout << result;
	}
	}
	return 0;
}


So I made this code for one of the questions my text books asks for, however it stops working as soon as it gets to a space in the string, and gives me an error that is very useless "Abort() has been activated". That being said it works for single words but for some reason still gives me an error. Its a very simple code and I don't feel this is my fault as it the lack of how much the book has actually taught me at this point.
Last edited on
closed account (28poGNh0)
I think you did put '1' instead of 'i' in for loop

for (int i = 0; 1 < input.length(); i++)
I see that -_- well that explains the error but not why it stops at spaces, am I missing some key element?
closed account (28poGNh0)
because 'cin >> ' keeps reading untill it encoutered a whitesspace (space ,tab,and newlines)

try to alter cin >> input; to getline(cin,input);
Last edited on
Topic archived. No new replies allowed.