- Joined
- Mar 30, 2013
- Messages
- 474
- Reaction score
- 56
http://pastebin.com/WAxU1Sxu
So, I have an array, arr[4], which can hold four words set into it from stringHolder. I want to break each word inputted into arr[4] into an array of characters. No clue how to do this, thanks to anyone who helps.
Code:
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
//global variables
string stringHolder = "";
string arr[4];
double option;
class Ascii {
public:
//outputs the options
void output() {
cout<< "1Encrypt-2Decrypt-3Both" << endl;
cin >> option;
cout << endl << "Enter String(Dont make it longer than four words):";
cin.ignore();
getline(cin,stringHolder);
}
//breaks string into words
void stringBreaker() {
int i = 0;
stringstream ssin(stringHolder);
while (ssin.good() && i < 4){
ssin >> arr[i];
++i;
}
for(i = 0; i < 4; i++) {
cout << arr[i] << endl;
}
}
//breaks string into char array
void charBreaker() {
}
//will output both encrypted and decrypted versions
string all() {
stringBreaker();
return (arr[1], " ", arr[2], " ", arr[3], " ", arr[4]);
}
//encrypts to ascii
string encyrpt() {
stringBreaker();
return (arr[1], " ", arr[2], " ", arr[3], " ", arr[4]);
}
//decrypts from ascii
string decrypt() {
stringBreaker();
return (arr[1], " ", arr[2], " ", arr[3], " ", arr[4]);
}
private:
//you dont have privates
};
int main() {
//local variables
string result;
string output;
Ascii ascii;
//output
ascii.output();
if (option == 1) {
result = ascii.encyrpt();
} else if(option == 2) {
result = ascii.decrypt();
} else {
result = ascii.all();
}
cout << "Result " << result;
system("Pause");
return 0;
}
So, I have an array, arr[4], which can hold four words set into it from stringHolder. I want to break each word inputted into arr[4] into an array of characters. No clue how to do this, thanks to anyone who helps.

