C++ How to create a class object that loops and increments by one? -


i have 3 files , output want not elegant.

is there way have object num (122) , num(554) output next number in sequence 5 times without having << cout << every time?

here main.cpp:

#include <iostream> #include "number.h"  using namespace std;  int main() {   number obj(122);    cout << nobj (122) << endl;   cout << nobj (123) << endl;   cout << nobj (124) << endl;   cout << nobj (125) << endl;   cout << nobj (126) << endl;    cout << nobj (554) << endl;   cout << nobj (555) << endl;   cout << nobj (556) << endl;   cout << nobj (557) << endl;   cout << nobj (558) << endl; } 

header file:

#ifndef number_h #define number_h  class number { public:     number(int numa);     int operator ()(int numb);      int numa; };  #endif 

number.cpp:

#include <iostream> #include "number.h"  using namespace std;   number::number(int numc): numa(numc) {}  int number::operator()(int numb) {     int = 0;      while(i < 10)     {         return numb += 1;         i++;     }  } 

output is:

123 124 125 126 127  555 556 557 558 559    

edited:

for(int = 0; < 5; ++i) {     cout << nobj (122+i) << endl; }  for(int = 0; < 5; ++i) {     cout << nobj (554+i) << endl; } 

i think function may you.

inline void print_nums(const size_t start_num, const size_t loop_times) { (size_t = 0; < loop_times; ++i) { std::cout << (start_num + i); std::cout << std::endl; } }


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -