Getting text for editing ...

This is a discussion on Getting text for editing ... within the C++ Programming forums, part of the General Programming Boards category; Hi, I was wondering if there's a way (and I'm sure there is, but I don't know what it is ...

  1. #1
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262

    Getting text for editing ...

    Hi,

    I was wondering if there's a way (and I'm sure there is, but I don't know what it is due to inexperience) open a file with in a program, and to print the text on the screen. This is simple of course, but what I wanted to know is whether there's a way to edit that which was in the file itself withing the console.

    We'll say I had a file in the C:\\ drive called test.txt and

    Code:
    Hi, this is a test!
    is written in the file. I know I could simply oped it up from within the program and edit it in whatever automatically opens text documents, and edit it there, but I would like to edit it in the console without having to retype "Hi, this is a test!" and delete most of it in order to change it to "Hi, I hope this works"

    Know what I mean?? Twomers

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Know what I mean??
    Nope.

  3. #3
    Pawn, Pascal and C++
    Join Date
    Sep 2005
    Posts
    90
    I belive he wants to open a text file in the msdos window, and being able to edit it there without a text editor.
    Pointless to me.

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Compiler/OS. You said C:\\ (You should know the \\ is only because you are escaping the character) so I am assuming Windows.


    Code:
    #include <windows.h>
    #include <stdio.h>
    
    void MouseChangeCursorPos(MOUSE_EVENT_RECORD mEr) 
    {
    	HANDLE hOut;
    	COORD cRt;
    
    	if(mEr.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
    	{
    		hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    		cRt = mEr.dwMousePosition;
    		SetConsoleCursorPosition(hOut, cRt);
    	}
    }
    void WriteKey(KEY_EVENT_RECORD kEr) 
    { 
    	if(kEr.bKeyDown)
    	{
    		if(
    			kEr.dwControlKeyState != LEFT_ALT_PRESSED &&
    			kEr.dwControlKeyState != LEFT_CTRL_PRESSED &&
    			kEr.dwControlKeyState != RIGHT_CTRL_PRESSED &&
    			kEr.dwControlKeyState != RIGHT_ALT_PRESSED &&
    			kEr.dwControlKeyState != SHIFT_PRESSED &&
    			kEr.uChar.AsciiChar)
    		
    		{
    			printf("%c", kEr.uChar.AsciiChar);
    		}
    	}
    } 
     
    int main(int argc, char *argv[]) 
    { 
    	HANDLE hIn; 
    	DWORD read, dwOld; 
    	INPUT_RECORD irBuf[128];
     
    	hIn = GetStdHandle(STD_INPUT_HANDLE);
    	GetConsoleMode(hIn, &dwOld);
    	SetConsoleMode(hIn, ENABLE_MOUSE_INPUT);
    
    	printf("Hello World!");
    
    	while(true) 
    	{
    		ReadConsoleInput(hIn, irBuf, 128, &read);
    		for (int i = 0; i < read; i++) 
    		{
    			if(irBuf[i].EventType == KEY_EVENT) 
    				WriteKey(irBuf[i].Event.KeyEvent);
    			if(irBuf[i].EventType == MOUSE_EVENT) 
    				MouseChangeCursorPos(irBuf[i].Event.MouseEvent);
    		}
    	} 
    
    	SetConsoleMode(hIn, dwOld);	
    	return 0; 
    }
    You can implement bounds checking and delete handling and undo's and all the fancy features of a text editor yourself? You will enjoy these API functions: http://msdn.microsoft.com/library/de..._functions.asp

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    106
    I think you want fstream.

  6. #6
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Tonto: Thanks a lot! that's a cool code, especially when you clock the mouse to where you want to go in the code. I actually found another way of doing it, well it's esentially the same thing to be honest, but without that nifty mouse thing.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 10:45 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21