Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include "container.h"
- using namespace std;
- int main()
- {
- container_t user;
- int count;
- int i;
- int size;
- char word;
- cout << "input the malloc size: " << endl;
- cin >> size ;
- char *str = (char*)malloc(sizeof(char) * (size+1));
- cout << "you want to show the word and time" << endl;
- cin >> str ;
- while(*str != '\0')
- {
- if(isalpha(*str))
- {
- word = *str;
- }
- else
- {
- count = atoi(str);
- for(i = 0 ; i < count; i++)
- {
- user.insert(word);
- }
- }
- str++;
- }
- user.all_delete();
- user.printlist();
- }
- ==============================================================================================
- //container.cpp
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- #include <iostream>
- #include <vector>
- #include "container.h"
- using namespace std;
- void container_t::insert(char c)
- {
- container.push_back(c);
- }
- char container_t::all_delete()
- {
- vector<char>::iterator itr;
- for(itr = container.begin(); itr != container.end(); itr++)
- cout << *itr << ' ';
- cout << '\n';
- }
- void container_t::printlist()
- {
- container.erase(container.begin(), container.end());
- if(container.empty())
- printf("Is empty\n");
- }
- //=========================================================================================
- //container.h
- #ifndef _LIB_PUSH_H_
- #define _LIB_PUSH_H_
- #include <vector>
- struct container_t
- {
- public:
- char all_delete();
- void insert(char);
- void printlist();
- std::vector<char> container;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement