Hi guys. I have basically written an encryption program that works perfectly except when I try to include punctuation. I narrowed down the problem to being something along the lines of this:
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string test;
cin >> test;
int i = 0;
while (i < test.length())
{
if (test[i] == '.')
{
cout << "a";
}
if (test[i] == ',')
{
cout << "b";
}
if (test[i] == ' ')
{
cout << "c";
}
i++;
}
return 0;
}
This is the input/output:
1 2
. , .
a
As you can see, if you enter ". , .", the output should be "acbca" but it doesn't work when there are any spaces. Any help would be much appreciated! Thanks in advance.
Okay thanks a lot... I totally forgot about that >.> I am trying to replicate a problem I am having in a different program thats too long to post here (I used getline() in the other program so I still don't know what the problem is!). Anyway thanks for the help :)