hi im trying out this code where i have to store two vectors info from 2 diffrent txt files including ',' and ';'and this has to be in the function so i can call it back in an other function please i need help ive been trying to working on this for weeks .the parameter has to be the file names too
it has to be in a one function thats why :( any way thanks for taking your time to help me if you can i can show you the reqviurement and get an small idea
* task is to read and store the story elements, from one (or more) text files, and store this data in appropriate variables. This data will be used to generate the randomised story lines in the next task. Create a function called createLists() and call it from the runMenu() function, when option [3] Read and Store Data from File is selected. This function must accept a filename as a parameter (“*.txt”) and successfully read and store the data. The data is to be stored in two collection variables named storyConnectors, and storyQuestions. You can choose to read the data from a single file, storing each data set in the different variables, OR read and store each data set with three separate calls to the same function with different arguments OR use another suitable method of your own devising*
The & means that the parameter 'filename' is passed by reference to the function. The 'filename' is a reference, not a copy.
That is optional. The function can be vector<string> createList( string filename, char separator ); if that is more comfy. (Just like salem c did made it.)
//for (unsigned int i = 0; i < storyQuestionss.size(); i++)
//{
// cout << storyQuestionss[i] << " " << endl;
//}
return storyConnectorss,storyQuestionss;
okay in here can you tell me where i should change? and i called out the function by changing the position of return i get the out put of the return after the , i need the out put of both im sorry if this is annoying you :( but is really hard for me cus i have no background when it comes to programming languages
> the thing is he doesnt allow us to use the code we havent learnt yet :(
You're never going to learn much if you're stuck with a snail pace teacher
1 2 3 4 5 6 7
// one vector is returned, and the other is stored through a reference parameter.
vector<string> createLists(string storyConnectors,string storyQuestions, vector<string> & storyConnectorss) {
// your code
// Don't declare a local storyConnectorss, it's already provided to you as a parameter.
return storyQuestionss;
}
Or (since you're not going to be using std::pair as suggested by Learner2)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
struct pair_of_vectors {
vector<string>storyConnectorss;
vector<string>storyQuestionss;
};
pair_of_vectors createLists(string storyConnectors,string storyQuestions ) {
// your code
// make a return result pair
pair_of_vectors pair;
pair.storyConnectorss = storyConnectorss;
pair.storyQuestionss = storyQuestionss;
return pair;
}
Since we're not on your course, it's hard to guess what your syllabus is, what you do know (or what you should know).