1
我沒有得到任何錯誤,但是我的輸出結果並不是我想要的。我想讓'東西+我'成爲向量的輸入。但我的輸出只是我最初的'東西'變量 - 1個字符。我的向量結構沒有按預期迭代
stuff
tuff
uff
ff
f
/0
/0
gello?
ello?
llo?
gello?
代碼:
#include <iostream>
#include <string>
#include <vector>
struct Playlist
{
std::string name;
} ;
int main()
{
std::vector<Playlist> playlist;
std::cout << "Input 10 stuff" << std::endl;
for(int i = 0; i < 10; ++i)
{
Playlist ok;
ok.name = "stuff " + i;
playlist.push_back(ok);
std::cout << playlist.size() << std::endl;
}
std::vector<Playlist>::iterator iter = playlist.begin();
while(iter != playlist.end())
{
std::cout << iter->name << std::endl;
++iter;
}
std::cout << "gello?" << std::endl;
std::vector::iterator iter = playlist.begin();
while(iter != playlist.end()) { std::cout << iter->name << std::endl; ++iter; }
std::cout << "gello?" << std::endl;
return 0;
}