While Loop Vectors (Xcode)

I cannot access the vector created inside the while loop but I need the entire while loop to finish before coutting the vector. It couts backwards if I put the for loop inside the while and thinks the vector is empty or not declared when I put it outside... Help!?

#include <iostream>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

int main () {

int decimal,digit;
char A,B,C,D,E,F,ZERO,ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE;
A = 'A';
B = 'B';
C = 'C';
D = 'D';
E = 'E';
F = 'F';
ZERO = '0';
ONE = '1';
TWO = '2';
THREE = '3';
FOUR = '4';
FIVE = '5';
SIX = '6';
SEVEN = '7';
EIGHT = '8';
NINE = '9';
cin >> decimal;
while (decimal > 0) {
vector<char> myvector;

digit = decimal%16;
if (digit==15) {
myvector.push_back(F);
}
else if (digit==14) {
myvector.push_back(E);
}
else if (digit==13) {
myvector.push_back(D);
}
else if (digit==12) {
myvector.push_back(C);
}
else if (digit==11) {
myvector.push_back(B);
}
else if (digit==10) {
myvector.push_back(A);
}
else if (digit==9) {
myvector.push_back(NINE);
}
else if (digit==8) {
myvector.push_back(EIGHT);
}
else if (digit==7) {
myvector.push_back(SEVEN);
}
else if (digit==6) {
myvector.push_back(SIX);
}
else if (digit==5) {
myvector.push_back(FIVE);
}
else if (digit==4) {
myvector.push_back(FOUR);
}
else if (digit==3) {
myvector.push_back(THREE);
}
else if (digit==2) {
myvector.push_back(TWO);
}
else if (digit==1) {
myvector.push_back(ONE);
}
else if (digit==0) {
myvector.push_back(ZERO);
}
decimal = decimal/16;

for (int i = 0; i < myvector.size(); i++) {
cout << myvector[i];
}
}
}
1. use code tags
2.
It couts backwards

that's what your loop does -insert rightmost digit first, you can use vector<T>::reverse_iterator to output your vector contents backward (ain't std::containers cool?) http://www.cplusplus.com/reference/stl/vector/rbegin/
3.
thinks the vector is empty or not declared when I put it outside...

you declared your vector inside the loop, that's where her scope is
Topic archived. No new replies allowed.