In your sample, you can replace instances of 'var' with int - since that's all they appear to hold.
As for the string initializations, they're just setting the string to contain the same character a number of times, right?
You could make your own function that filled or created them. Here's one to just set them - your code never hangs onto them - it just passes them to conole.write.
So, make sure you have a std:string object first, then pass it to this function.
void setString(string &input, char newChar, int reps)
{
input = "";
int i;
for (i=0; i<reps; i++)
input = input + newChar;
}
A quick sample:
#include <iostream>
using namespace std;
void setString(string &input, char newChar, int reps)
{
input = "";
int i;
for (i=0; i<reps; i++)
input = input + newChar;
}
int main()
{
string testMe;
setString(testMe, '*', 10);
cout << testMe << endl;
setString(testMe, '-', 10);
cout << testMe << endl;
}
Output:
**********
----------