How detect that when enter key is pressed

#include
#include
using namespace std;
void con(vector v,int j)
{
if((v.size()-1)==j )
{
for(int i=0;i<v.size();i++)
{
cout<<v[i];
}
return;
}
if(v[j]==β€˜p’ and v[j+1]==β€˜i’)
{v[j]=β€˜3’;
v[j+1]=’.’;

v.insert(v.begin()+j+2,1,β€˜1’);
v.insert(v.begin()+j+2,1,β€˜4’);
j=j+3;
}else
j++;
con(v,j);
return;
}

int main()
{int t;
cin>>t;
while(t–)
{
vector v;
char x;

while(cin>>x)
{
    v.push_back(x);
    
    
}

//
con(v,0);
}

}

this is my code for this problem pl… I want to do this with vector only

https://ide.codingblocks.com/s/238195 code

https://ide.codingblocks.com/s/238195 code

this is my code for this problem pl… I want to do this with vector only

@lakshaygarg128 i dont understand your question? where are you trying to detect the enter? if you are taking input by cin then you dont have to worry about it. Otherwise enter is represented by β€˜\n’ newline character. Please elaborate a bit if you have any further question.

pl. check the code for the problem and tell my mistake u will understand my question

@lakshaygarg128 you can use string instead, it works dynamically like a vector but it is better suited for handling characters.

1 Like

Cant i do it with the vector?

Yes i know but i was trying it with vector

@lakshaygarg128 it is a tad bit difficult to read the input with vectors because if it is a character vector it will read only one character at a time and you dont know when to stop reading. So you can put a condition that’ll process the vector if the input character is β€˜\n’
please note that with this approach it is not guaranteed that you will be able to read the last input properly (you can check for EOF end of file character then)
Anyhow, I’d advise you to use strings for this question :slight_smile: