1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
void printMeHere(string Str, int iTextPositionX, int iTextPositionY, int iFieldWidth)
{
int lengthofsting = Str.length();
iFieldWidth = iFieldWidth + lengthofsting;
cout.width(iFieldWidth / 2);
COORD coordPos;
coordPos.X = iTextPositionX;
coordPos.Y = iTextPositionY;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coordPos);
cout << Str;
}
int main ()
{
cout << " Please type something"<<endl;
string myString;
cin >> myString;
printMeHere(myString, 2, 3, 10);
printMeHere("bbb", 2, 4, 10);
printMeHere("ccccc", 2, 5, 10);
printMeHere("gggggggggg", 2, 6, 10);
cout << "\n\nHit the enter key to exit.\n";
cin.get();
return 0;
}
| |