Why can not getline?
When you input the value for input length you enter a number and a newline, that newline is get by getline
If you entered for instance 123 aze qsd then strPass will be " aze qsd"
So you get a line, but not the expected one
If you want to flush all after the number on the same line you can double getline call
For instance also modifying your code to see more :
#include <iostream>
#include <string>
using namespace std;
int main()
{
int len;
cout << "input length : ";
cin >> len;
int* intPass = new int[len];
int* intSolu = new int[len];
string strPass;
getline(cin, strPass);
getline(cin, strPass);
cout << "strPass is " << strPass << endl;
cout << "intPass input :" << endl; // it is an input, not an output
for (int i = 0; i < len; i++) {
cin >> intPass[i];
}
cout << "intPass output is" << endl;
for (int i = 0; i < len; i++) {
cout << intPass[i] << endl;
return 0;
}
Compilation and execution :
pi@raspberrypi:~ $ g++ -pedantic -Wall -Wextra c.cc
c.cc: In function ‘int main()’:
c.cc:13:8: warning: unused variable ‘intSolu’ [-Wunused-variable]
int* intSolu = new int[len];
^~~~~~~
pi@raspberrypi:~ $ ./a.out
input length : 3
aze qsd
strPass is aze qsd
intPass input :
11
22
33
intPass output is
11
22
33
pi@raspberrypi:~ $
I encourage you to check if cin >> len
success and if yes to check the value of len, for instance :
if (!(cin >> len) || (len < 0)) {
cout << "invalid length" << endl;
return -1.
}