は、だから私はstd::vector<int> WidthNumbers = 320, 640, 1280;
ような何かをしようが、あなたのコンパイラがC++ 0xのをサポートしている場合、コンパイラは私にエラーC2440: 'int' to 'std::vector<_Ty>'
std :: vectorのエラーを修正する方法<int> WidthNumbers = 320,640,1280 ;,
答えて
を使用することができますがすることはできませんその構文を使用してvector
を初期化します。 C++ 0xでは、次のものを使用できるようにするイニシャライザリストを使用できます。
std::vector<int> WidthNumbers = {320, 640, 1280};
これはVS2010では実装されていません。選択肢は次のとおりです。
int myArr[] = {320, 640, 1280};
std::vector<int> WidthNumbers(myArr, myArr + sizeof(myArr)/sizeof(myArr[0]));
OR
std::vector<int> WidthNumbers;
WidthNumbers.push_back(320);
WidthNumbers.push_back(640);
WidthNumbers.push_back(1280);
最初のオプションを使用する場合、次のテンプレートが便利です: 'template
を与える(MSVC++ 2010がpartial support for C++0xを持っている)あなたはinitializer list
std::vector<int> WidthNumbers = {320, 640, 1280};
しかし、VC++ 2010の部分的サポートはこの機能を含みません。 –
あなたはまた、boost::assign::list_of
#include <boost/assign/list_of.hpp>
#include <vector>
int
main()
{
typedef std::vector<int> WidthNumbers;
const WidthNumbers foo = boost::assign::list_of(320)(640)(1280);
}
を使用することができますこれは少しより多くの仕事ですが、私はそれがVS 2010と非常によく動作します見つけます。イニシャライザリストを使用する代わりに、_vector.push_back()
メソッドを使用してベクトルにアイテムを手動で追加することができます。
//forward declarations
#include <vector>
#include <iostream>
using namespace std;
// main() function
int _tmain(int argc, _TCHAR *argv)
{
// declare vector
vector<int> _vector;
// fill vector with items
_vector.push_back(1088);
_vector.push_back(654);
_vector.push_back(101101);
_vector.push_back(123456789);
// iterate through the vector and print items to the console
vector<int>::iterator iter = _vector.begin();
while(iter != _vector.end())
{
cout << *iter << endl;
iter++;
}
// pause so you can read the output
system("PAUSE");
// end program
return 0;
}
これは、ブーストを使用することができ、それは常に
- 1. エラー2664 - std :: vector <...>をstd :: tr1 :: shared_ptr
- 2. C++、正しくコピーする方法std :: vector <Class *>コピーコンストラクタで?
- 3. C++のstd :: vectorをstd :: vector <unsigned char>に変換する
- 4. std :: vector <std::string>クラッシュ
- 5. std :: vectorを "cast"する方法<wchar_t>
- 6. std :: vector <std :: vector <int>> push_backによりヒープバッファオーバーフローが発生する
- 7. `std :: vector <std :: uint8_t>の高速コピー
- 8. DynamicJasper:java.lang.NoSuchMethodErrorエラーの修正方法
- 9. 反復::ベクトル<std :: vector <char>>?
- 10. 修正する方法のjava.lang.NullPointerExceptionエラー?
- 11. `std :: vector <uchar>`を `std :: ostream`に保存するには?
- 12. std :: std :: stringとstd :: vectorの間の移動<unsigned char>
- 13. SQLエラー1064 - 修正方法?
- 14. std :: vectorの代わりに<uint16_t>のstd :: vectorにバイナリファイルを読み込みます。<char>
- 15. boost :: ptr_containerとstd :: vector <shared_ptr>
- 16. qsort on std :: vector <float*> _data
- 17. std :: vectorのカスタムアロケータ
- 18. std :: vectorをstd :: valarrayに代入する
- 19. `std :: set`の要素に基づいて` std :: vector`をスライスする方法
- 20. std :: vector <decltype(iter)> - decltypeの有効な使用法?
- 21. C++ - std :: vectorの新しいコンストラクタを作成する<double>?
- 22. C++ std :: vector problems
- 23. std :: vector resize down
- 24. sizeof()std :: vector(C++)
- 25. boost :: interprocess - std :: string vs std :: vector
- 26. ファイルをstd :: vectorに読み込む効率的な方法<char>?
- 27. std :: vectorの問題
- 28. C#でフォームのリソースファイルのエラーを修正する方法
- 29. postgresqlの削除中にこのエラーを修正する方法
私の作品、私は個人的にベクトルを宣言し、初期化する方法はありますか? –
はい私はboost =を使用することができます=) – Rella