Recursion Subsequences

this is my code

#include
#include
using namespace std;

int cnt=0;
void subsequences(string str,int i,int j,vectorv){

 if(str[i]=='\0'){
	 v.push_back('\0');
	 cnt++;
	 for(auto x:v){
		 cout<<x;
	 }
	 cout<<" ";
	 return;
 }


 subsequences(str,i+1,j,v);
 v.push_back(str[i]);
 subsequences(str,i+1,j+1,v);

}
int main() {
string str;
cin>>str;
vectorv;
subsequences(str,0,0,v);
cout<<endl<<cnt;
return 0;
}

there are some mistakes in your code

  1. no need to use vector ,string can be better suited
  2. after pushing element you also have to pop

check the modified Code below
Modified Code

#include<iostream>
#include<vector>
using namespace std;

int cnt = 0;
void subsequences(string str, int i, int j, string out) {
	if (str[i] == '\0') {
		cnt++;
		cout<<out<<" ";
		return;
	}

	subsequences(str, i + 1, j, out);
	out.push_back(str[i]);
	subsequences(str, i + 1, j + 1, out);
	out.pop_back();
}
int main() {
	string str;
	cin >> str;
	vector<char>v;
	subsequences(str, 0, 0, "");
	cout << endl << cnt;
	return 0;
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.