Binary sequence in lexicographic order
Here is my assigment's problems:
Required: Write a C++ program that writes all binary sequences of length 15 in increasing lexicographic order into a file "binary15.txt".
My solution so far is like this:
vector<int>v(15);
for(int i=0; i<v.size(); i++)
cout << v[i];
cout << endl;
v.pop_back();
v.push_back(1);
for(int i=0; i<v.size(); i++)
cout << v[i];
cout << endl;
v.pop_back();
v.pop_back();
v.push_back(1);
v.push_back(0);
for(int i=0; i<v.size(); i++)
cout << v[i];
cout << endl;
v.pop_back();
v.push_back(1);
for(int i=0; i<v.size(); i++)
cout << v[i];
cout << endl;
However, the output only shows the first 4 lines of the binary sequence of length 15 each and I realize if I am going to write all the sequences, the commands that I have to repeat if using vector are too abundant.
Anyone have better idea of how to do this question in a smarter way? I have to submit the assignment by tomorrow. Hope anyone of you may help me in this. Thank you.