Email: bknpk@hotmail.com Phone: +972-54-7649119


V

 

This page presents a simpe example of using a double ended STL container. It is implemented as part of a c++ series of exercises , that I did.

  1. The example has simple class, with two fields, float and a string. First the deque is filled and then printed.
    In this example an integer is converted to string using a ostringstream.

    1. #include <iostream>
    2. //setw setfill
    3. #include <iomanip>
    4. #include <sstream>
    5. #include <string>
    6. #include <cassert>
    7. #include <deque>
    8. using namespace std;
    9. class c_block_member {
    10.   public:
    11.     c_block_member(string name, float f);
    12.     string nm;
    13.     float fp;
    14. };
    15. c_block_member::c_block_member(string name, float f) {
    16.   nm=name.substr(0);
    17.   fp=f;
    18. }
    19. int main() {
    20.   deque<c_block_member> q_block_member;
    21.   c_block_member *bm;
    22.   unsigned i;
    23.   ostringstream os_inst;
    24.   string s_inst;
    25.   //build deque
    26.   for(i=1; i<=10; ++i) {
    27.     //default fill is space
    28.     os_inst << "U_" << setfill ('0') << setw (8) << i;
    29.     s_inst=os_inst.str();
    30.     os_inst.str(""); os_inst.clear();
    31.     bm = new c_block_member(s_inst, i*(1.2));
    32.     q_block_member.push_back(*bm);
    33.   }
    34.   delete bm;
    35.   //print deque
    36.   deque<c_block_member>::iterator it;
    37.   cout << "dbg " << endl;
    38.   for (it = q_block_member.begin(); it!=q_block_member.end(); ++it) {
    39.     cout << it->nm << ";" << (*it).fp << endl;
    40.   }
    41. }

  2. To view the content of the deque container, the following gdb commands can be used:
    p *(q_block_member._M_impl._M_start)
    p *(q_block_member._M_impl._M_finish)
    print "%f\n", *(q_block_member._M_impl._M_start)
    print "%f\n", (q_block_member._M_impl._M_start)[0]
    print "%f\n", (q_block_member._M_impl._M_start)[1]

  ...



Home

some memory VHDL models


A simple c-code program to read a memory array from verilog RTL, using VPI.



Download Area







Search This Site


Feedback This Site




new pages on this site