Does anyone know how to type something with C++?

Hello, the topic is self-explanatory.
I want to be able to type something using C++, after cin'ing it.

Is there a way to do this?
I'm not sure of what you mean. If you read from cin you have already typed it. Do you mean printing it back to the console?
I mean typing it externally, like I want to cin something to actually be typed.

For example, if I cin "Hello", I want C++ to be able to type "Hello" into notepad or an external program. Is this possible?
Oh I see. Sorry, but I have no idea. If it is possible it is definetly not something at beginner level.
Oh, alright. Thanks anyway.
Sounds like you mean to output to the txt file after you input each character? Maybe try conio or another library. But for it to actually "update" the text file you have to close it and reopen the text file. I guess you could use the library also to close the txt file and reopen each time here is a snippet that you might be looking for?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>
#include <conio.h>

int main()
{
    std::ofstream out( "output.txt" , std::ios::app );
    std::cout << "enter stuff\n> " << std::flush;
    char temp( ' ' );
    while( static_cast<int>( temp = getch() ) != 13 )
    {
            std::cout << temp << std::flush;
            out << temp << std::flush;
    }
}


If you mean to output all of it at one time that would be very simple.

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <fstream>

int main()
{
    std::fstream out( "output.txt" );
    std::string temp;
    std::cin >> temp; //I would suggest getline and not cin..
    out << temp;
}
Yeah, I was going to answer with some file io code too, but wasn't sure. That is what I thought he meant, but he very well could mean is it possible to run a program that takes input at the terminal and writes it into notepad for him in real time. The first is easy to do, but the latter I'm not sure if it is possible.
He wants to inject text into another running application's input queue. This requires some Windows API programming. The question is answered in OP's other thread here:
http://www.cplusplus.com/forum/general/105510/
Topic archived. No new replies allowed.