SQL

Friday, 29 January 2016

vector and resize vector in C++

This Example will demonstrate C++11 or above vector and how to use it. This following creates a vector of fixed size and calculate the sum. vector_size.cpp is the c++ file. You may also rename it to vector_size.cxx


hasan@lucid:~/Desktop/cpp/vector$ g++ -std=c++11 vector_size.cpp
hasan@lucid:~/Desktop/cpp/vector$ ./a.out
Entera value
1.1
Entera value
2.4
Entera value
3.5

sum = 7



This example will demonstrate how to resize the previous vector we created and calculate the sum.



hasan@lucid:~/Desktop/cpp/vector$ g++ -std=c++11 vector_size.cpp
hasan@lucid:~/Desktop/cpp/vector$ ./a.out
Number of values to Sum?
3
Entera value
1.1
Entera value
2.2
Entera value
3.3

6.6
hasan@lucid:~/Desktop/cpp/vector$


Post a Comment