Hello. I am trying to create a vector with 4 strings in them. The first string is "apple", second being "banana", third being "orange" and the fourth being "strawberry". I tried the following command:
vector fruit("apple", "banana", "orange", "strawberry") ; but this did not work.
I am using this for the private part of a class I am creating. Please help
A new feature in the upcoming revision to the C++ standard will allow you to initialize the vector in the same way as an array, like this:
vector fruit = { "apple", "banana", "orange", "strawberry" };
But this feature is not yet widely supported, try it on your compiler and see. I believe the latest version of GCC supports it.
?
2016-10-18 12:31:27 UTC
Vector String
?
2015-08-14 18:35:13 UTC
This Site Might Help You.
RE:
how do you create a vector of strings in c++?
Hello. I am trying to create a vector with 4 strings in them. The first string is "apple", second being "banana", third being "orange" and the fourth being "strawberry". I tried the following command:
vector<string> fruit("apple",...
iskyfire
2011-04-11 18:01:37 UTC
You can use this code as a start. Make sure to include the right header files.
#include
#include
#include
using namespace std;
#include
int main() {
keepr dontstop;
vector list;
string word;
ifstream wordfile("dic.dat");
while (infile >> word) {
list.push_back(word);
}
for (unsigned n=0; n cout << list.at( n ) << " ";
}
return 0;
}
slafond
2011-04-11 18:11:50 UTC
Not sure of the answer, still searching but you may want to try some of the forums out there. I do know that in C++ I have not seen the complete word - string - referenced. char, strcpy, str, etc. but not the actual word string. Are you doing this from a text book?
anonymous
2016-03-16 07:24:23 UTC
What do you really want? I think your statements and code is too ambiguous. Anyhow, add a switch statement such that if the character is vowel dont add to s.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.