Cursor Movement

hi

Can anybody tell me how to move the cursor in the console window after taking an input from the keyboard.
like
1
2
3
4
5
6
7
string name;
for(int i=0;i<5;i++)
{
  cout<<"\t";
  cin>>name;
  cout<<"\t";
}


what i mean is i want to take the names side by side

Robert Rakesh Raamu
If i press enter then the cursor automatically moving to the new line , but i need to move it by certain number of positions in the same line.

Thanking you in advance.......
Last edited on
You can't do that with standard C++.
You could try doing it this way. This compiles and runs under MS Visual C++ 2008 Express Edition. If you're using something else, you may need to make a few changes.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Names.cpp : Defines the entry point for the console application.
//

#include <stdafx.h>
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;


void gotoXY(int,int);
void gotoXY(int,int,string);

int _tmain(int argc, _TCHAR* argv[])
{
	string name;
	gotoXY(6,3,"Please enter three names.");
for(int i=0;i<3;i++)
	{
		gotoXY(i*10,8);
		cin>>name;
	}
return 0;
}

void gotoXY(int x, int y) 
{ 
CursorPosition.X = x; 
CursorPosition.Y = y; 
SetConsoleCursorPosition(console,CursorPosition); 
}

void gotoXY(int x, int y, string text) 
{ 

CursorPosition.X = x; 
CursorPosition.Y = y; 
SetConsoleCursorPosition(console,CursorPosition);
cout << text;
}
Thanking you Its working exactly.................
@Srija

You're welcome. You may now want to update this thread as 'Solved'.
Topic archived. No new replies allowed.