From 74bf3e2ec7e02d1468444a6f2236e35b24af0def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sat, 20 Sep 2014 20:35:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dvector=E5=BD=93=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E6=98=AFstd::string=E6=97=B6=E7=9A=84=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E4=BA=8C=E4=B9=89=E6=80=A7bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/UninitializedFunctions.h | 2 +- TinySTL/Vector.h | 2 +- TinySTL/main.cpp | 11 ++++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/TinySTL/UninitializedFunctions.h b/TinySTL/UninitializedFunctions.h index 21eb9f3..1bb4d5c 100644 --- a/TinySTL/UninitializedFunctions.h +++ b/TinySTL/UninitializedFunctions.h @@ -90,7 +90,7 @@ namespace TinySTL{ ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first, Size n, const T& x, _false_type){ int i = 0; - for (; i != n;){ + for (; i != n; ++i){ construct((first + i), x); } return (first + i); diff --git a/TinySTL/Vector.h b/TinySTL/Vector.h index 646f364..412c8ee 100644 --- a/TinySTL/Vector.h +++ b/TinySTL/Vector.h @@ -151,7 +151,7 @@ namespace TinySTL{ private: void allocateAndFillN(const size_type n, const value_type& value){ start_ = dataAllocator::allocate(n); - uninitialized_fill_n(start_, n, value); + TinySTL::uninitialized_fill_n(start_, n, value); finish_ = endOfStorage_ = start_ + n; } template diff --git a/TinySTL/main.cpp b/TinySTL/main.cpp index cb4b453..aabf459 100644 --- a/TinySTL/main.cpp +++ b/TinySTL/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "Allocator.h" #include "Construct.h" @@ -11,12 +12,8 @@ using namespace std; int main(){ - int array[3] = { 1, 2, 3 }; - TinySTL::vector vec(array, array + 3); - //TinySTL::vector vec(3, 1); -> error C2019 - cout << *(vec.begin()) << endl; - cout << *(++vec.begin()) << endl; - cout << *(--vec.end()) << endl; + TinySTL::vector svec(10, "hello world"); + for (auto s : svec){ cout << s << endl; } system("pause"); return 0; -} \ No newline at end of file +}