I am attempting to write some C++ code in which a command allows interactive users to enter 6 letters that will appear each take a side of a dice. There can be an unlimited amount of dice, but there will always be 6 letters, one for each side of the dice. I am currently using a 2-dimensional vector to store the information, however I am not sure if there is a better approach to this. My current approach is giving me a segmentation fault.
string word;
string cube;
vector<vector<char>> v;
int c = 0;
cout << "Please enter 6 letters with no spaces." << endl;
cin >> cube;
transform(cube.begin(), cube.end(), cube.begin(), ::toupper);
while(cube.length() != 6){
cout << cube << " is not 6 letters" << endl;
cin >> cube;
transform(cube.begin(), cube.end(), cube.begin(), ::toupper);
}
cout << cube << endl;
for(int i = 0; i < 6; i++){
v[c][i] = cube.at(i);
}
c++;
this is all placed inside a while loop so that the vector can keep being filled.
Aucun commentaire:
Enregistrer un commentaire