Hello! I was wondering if there was a command in C++, specifically visual C++ .net 2003, in which I can take what was partially entered in the console and save it to a variable before the user presses enter. I am creating a mini-irc and I want to store what was partially input by the user before clearing the chat window and refreshing the text inside of it. I can figure it all out but this last step. Any help is greatly appreciated!!
caut_baia 9 Posting Whiz
Check out Stringstreams and give it a shot.If you don't post code some of us can't help...
gamer88 0 Newbie Poster
#include <iostream>
#include <windows.h>
#include <string>
#include <fstream>
#include <time.h>
#include <process.h>
#include <stdlib.h>
using namespace std;
//random variables that are global, can include counters that need to be global and of course the fstreams of the mainchat text
ofstream mainchat_out;
ifstream mainchat_in;
string mainchat_lastline;
int refreshcounter = 0;
string line[101];
int loldelay;
DWORD WINAPI MyThreadTextchecker( LPVOID lpParam );
//Gets the username of the user
void usernameget()
{
//LOL CODE GOES IN HERE
}
void getalllines()
{ //Let me just start this out by saying that this will take FUCKING FOREVER TO CODE
//The fun of these 101 lines of code will be unmesserable
getline(mainchat_in, line[1]);
getline(mainchat_in, line[2]);
getline(mainchat_in, line[3]);
getline(mainchat_in, line[4]);
getline(mainchat_in, line[5]);
getline(mainchat_in, line[6]);
getline(mainchat_in, line[7]);
getline(mainchat_in, line[8]);
getline(mainchat_in, line[9]);
getline(mainchat_in, line[10]);
getline(mainchat_in, line[11]);
getline(mainchat_in, line[12]);
getline(mainchat_in, line[13]);
getline(mainchat_in, line[14]);
getline(mainchat_in, line[15]);
getline(mainchat_in, line[16]);
getline(mainchat_in, line[17]);
getline(mainchat_in, line[18]);
getline(mainchat_in, line[19]);
getline(mainchat_in, line[20]);
getline(mainchat_in, line[21]);
getline(mainchat_in, line[22]);
getline(mainchat_in, line[23]);
getline(mainchat_in, line[24]);
getline(mainchat_in, line[25]);
getline(mainchat_in, line[26]);
getline(mainchat_in, line[27]);
getline(mainchat_in, line[28]);
getline(mainchat_in, line[29]);
getline(mainchat_in, line[30]);
getline(mainchat_in, line[31]);
getline(mainchat_in, line[32]);
getline(mainchat_in, line[33]);
getline(mainchat_in, line[34]);
getline(mainchat_in, line[35]);
getline(mainchat_in, line[36]);
getline(mainchat_in, line[37]);
getline(mainchat_in, line[38]);
getline(mainchat_in, line[39]);
getline(mainchat_in, line[40]);
getline(mainchat_in, line[41]);
getline(mainchat_in, line[42]);
getline(mainchat_in, line[43]);
getline(mainchat_in, line[44]);
getline(mainchat_in, line[45]);
getline(mainchat_in, line[46]);
getline(mainchat_in, line[47]);
getline(mainchat_in, line[48]);
getline(mainchat_in, line[49]);
getline(mainchat_in, line[50]);
getline(mainchat_in, line[51]);
getline(mainchat_in, line[52]);
getline(mainchat_in, line[53]);
getline(mainchat_in, line[54]);
getline(mainchat_in, line[55]);
getline(mainchat_in, line[56]);
getline(mainchat_in, line[57]);
getline(mainchat_in, line[58]);
getline(mainchat_in, line[59]);
getline(mainchat_in, line[60]);
getline(mainchat_in, line[61]);
getline(mainchat_in, line[62]);
getline(mainchat_in, line[63]);
getline(mainchat_in, line[64]);
getline(mainchat_in, line[65]);
getline(mainchat_in, line[66]);
getline(mainchat_in, line[67]);
getline(mainchat_in, line[68]);
getline(mainchat_in, line[69]);
getline(mainchat_in, line[70]);
getline(mainchat_in, line[71]);
getline(mainchat_in, line[72]);
getline(mainchat_in, line[73]);
getline(mainchat_in, line[74]);
getline(mainchat_in, line[75]);
getline(mainchat_in, line[76]);
getline(mainchat_in, line[77]);
getline(mainchat_in, line[78]);
getline(mainchat_in, line[79]);
getline(mainchat_in, line[80]);
getline(mainchat_in, line[81]);
getline(mainchat_in, line[82]);
getline(mainchat_in, line[83]);
getline(mainchat_in, line[84]);
getline(mainchat_in, line[85]);
getline(mainchat_in, line[86]);
getline(mainchat_in, line[87]);
getline(mainchat_in, line[88]);
getline(mainchat_in, line[89]);
getline(mainchat_in, line[90]);
getline(mainchat_in, line[91]);
getline(mainchat_in, line[92]);
getline(mainchat_in, line[93]);
getline(mainchat_in, line[94]);
getline(mainchat_in, line[95]);
getline(mainchat_in, line[96]);
getline(mainchat_in, line[97]);
getline(mainchat_in, line[98]);
getline(mainchat_in, line[99]);
getline(mainchat_in, line[100]);
getline(mainchat_in, line[101]);
}
void outputalllines() /*This program outputs the line, as long as it is not blank, and will output the last non-blank line*/
{ /* into a variable called mainchat_lastline */
/*if (line[1] != "")
{
cout << line[1] << endl;
}
else
{
cout << "Welcome to the chatroom, no one has talked... why not try doing so?" << endl;
}
//Line2
if (line[2] != "" && line[1] != "")
{
cout << line[2] << endl;
}
else
{
line[1] >> mainchat_lastline;
}
Line3
if (line[3] != "")
{
cout << line[3] << endl;
}
else
{
NoJoyFunction();
}
//Line4
if (line[4] != "")
{
cout << line[4] << endl;
}
else
{
NoJoyFunction();
}
//Line5
if (line[5] != "")
{
cout << line[5] << endl;
}
else
{
NoJoyFunction();
}
*/
}
DWORD WINAPI MyThreadTextchecker( LPVOID lpParam )
{
//LOL CODE GOES IN HERE
system("CLS");
cout << "test lol!!!!" << endl;
return 0;
}
int main()
{
//Opens the text files of the mainchat for input and output
mainchat_out.open("C:\\mainchat.txt", ios::app);
mainchat_in.open("C:\\mainchat.txt");
//gets the username from the function usernameget
//usernameget();
//refreshes the textbox text...
//A temparary main function
//The following is my attempt at a thread inside of the main thinger.
DWORD checktextident;
HANDLE checkingtextthread;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
cout << "LOL IZ IN YOUR CONSOLES, MESSING UP YOUR CODEZ" << endl;
system ("PAUSE");
checkingtextthread = CreateThread(
NULL, // default security attributes
0, // use default stack size
MyThreadTextchecker, // thread function name
NULL, // argument to thread function
0, // use default creation flags
&checktextident); // returns the thread identifier
//http://msdn.microsoft.com/en-us/library/ms682516(v=vs.85).aspx
//http://msdn.microsoft.com/en-us/library/ms686736(v=vs.85).aspx
//http://msdn.microsoft.com/en-us/library/ms682453(v=vs.85).aspx
//http://www.daniweb.com/forums/thread37185.html
mainchat_in.close();
mainchat_out.close();
while(loldelay < 1200000000)
{
loldelay++;
}
return 0;
}
This code has not been cleaned up at all. Basically it checks to see if any lines have been added to a text file with a thread (later it will do this) and outputs the new lines in the console window, but to do this I have to either wait until they are done typing (which could be a long time) or force a cin statement or something simmilar.
caut_baia 9 Posting Whiz
I don't really get what you are trying to do but from a first look i'd say you could replace the first 200 lines with these :
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
int main () {
std::fstream i ("main.cpp",std::ios::in);
std::vector<std::string> vec;
std::string str;
while (getline(i,str)) {
vec.push_back(str);
}
}
For the rest i don't get what you're trying to do.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.