私は構造体の空のベクトルを使用しています。C++:vectorof structs
今、structメンバーの1つにデータを入力しているときに、ベクターのサイズが変更されますか?
はいの場合、イテレータをどのように初期化する必要がありますか? 私は実行時エラーがあり、私の推測は私のイテレータが無効であることです。
いくつかの関連するコード:
struct wordstype
{
string word;
int counter_same;
int counter_contained;
int counter_same1;
};
std::vector<wordstype>::iterator iv=vec1.begin();
string temp_str;
string::iterator is=str1.begin();
while (is!=str1.end())
{
if (((*is)!='-')&&((*is)!='.')&&((*is)!=',')&&((*is)!=';')&&((*is)!='?')&&((*is)!='!')&&((*is)!=':'))
{
temp_str.push_back(*is);
++is;
}
else
{
(*iv).word=temp_str;
++iv;
str1.erase(is);
temp_str.clear();
}
}
[C++:構造体メンバにデータを挿入する方法(vector内に配置された構造体)](http://stackoverflow.com/questions/10208367/c-how-to-insert-data-to-a) -struct-member-struct-located-in-vector) –
新しい質問を投稿するのではなく、元の質問を編集する必要があります。 –
基本的に、wordsTypeにデータを取得し、vec1.push_back(wordsTypeObj)を実行します。それは安全です。 – Jagannath