![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
hello again...im making a little command line and need a little help... well, fist ill show the code, then the questions! (1 question actualy)
![]() #include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
string line;
cout << "EasyCommand v. 1.0.0 BETA\n";
cout << "Copyright (c) 2005-2006\n";
cout << "Type 'help' for help\n\n";
do {
cout << ": ";
cin >> line;
if (line == "exit"){
return 0;
}
if (line == "box"){
string buffer;
cout << "\nEnter a title: ";
cin >> buffer;
string buffertwo;
cout << "\nEnter the text: ";
cin >> buffertwo;
MessageBox(NULL, buffertwo, buffer, 0);
}
if (line == "clear"){
system("cls");
cout << "\n";
}
if (line == "pause"){
system("pause");
cout << "\n";
}
if (line == "help"){
cout << "\nBOX Used to display a simple messagebox\nExample - Box (Output)Title: TitleHere (Output)Text: TextHere\nCLEAR Used to clear the console screen\nExample - clear\nEXIT Used to exit the console\nExample - exit\nHELP Used to display a list of commands\nExample - help\nPAUSE Used to pause the console \nExample - pause\n";
}
} while (line != "exit");
cout << "Exiting...";
return 0;
}ok, when i try to compile that, i get this error: Quote:
![]() |
|
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
In the message box, you can't use a string - you have to use a character array. You do this by converting the string to the array when you need it:
buffertwo becomes buffertwo.c_str() - this converts it into a C-style string (AKA a character array). |
|
|
|
|
|
#3 | |
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
hey! thanks Ooble! works great now... except one thing
i had to change it to char, but before i did, i tried what you told me, but when i chose a title or the text there could be no spaces, because anything after the space wouldnt show up, so heres how i approched it: if (line == "box"){
char buffer[100];
cout << "\nEnter the text: ";
cin.getline(buffer,100);
char buffertwo[100];
cout << "\nEnter the title: ";
cin.getline(buffertwo,100);
MessageBox(NULL, buffer, buffertwo, 0);
}now that works great, but it always skips the text section, it will be like this: Quote:
![]() |
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
to explain it a little better... it doesnt let the user input anything for the text, it skips right over that and goes to title... please ask if you do not understand, i will explain it better if needed :o
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
changing your line to this:
MessageBox(NULL, buffertwo.c_str(), buffer.c_str(), 0); works fine for me... could you explain your last problem a bit more, if this does not resolve it?
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
but see, heres the thing, if i use that... then if i type in "Hello World!", ONLY Hello shows up... sooo... any suggestions
and while im here... ill ask this... how do i split a string in C++? lets say i typed in this to the console: "box TitleHere TextHere"... is there a way i can split that up so that i would end up with something like: string title = TitleHere; string text = TextHere; ? for now im going to try to google it, but if i could figure this out, then that would solve my first question.. so im going to reasearch it, but if anyone else knows, could you please share? thanks a bunch (please tell me if im asking too much) ![]() |
|
|
|
|
|
#7 | |
|
Programmer
Join Date: Mar 2005
Location: USA
Posts: 60
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() ![]() |
as far as what the user types in... look into using the getline() function for your line variable.
The splitting of strings is possible via the standard template library... there are also a few snippets on the web that brute force it by looking for white space in character arrays and such.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
thanks guys... i think i got all the info i need now.. although i may be posting back later, so keep checking the forums!
but ive found a string splitting solution heres the website i got it at : http://www.codeguru.com/Cpp/Cpp/stri...cle.php/c9279/although i had to remove the _T and Console::WriteLine because the _T gave me erros, but i removed it and it worked fine and, for Console::WriteLine i dont know if it would have worked or not but i just used cout thanks a million guys! (when im finished with this project, i will be posting it in the "Finished Projects" section, but i dont know when it will be finished, maybe tonight, maybe in a week, i cant tell the future, only sometimes!) |
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
k, i lied, now im getting frusterated! could someone please explain to me, why i get this error when trying to compile this code...:
#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;
void strtoktest()
{
char input[] = line;
char delimiters[] = ("print ");
for (char* token = strtok(input, delimiters);
token != NULL;
token = strtok(NULL, delimiters))
{
cout << "\n";
cout << (token);
}
}
int main()
{
string line;
cout << "EasyCommand v. 1.0.0 BETA\n";
cout << "Copyright (c) 2005-2006\n";
cout << "Type 'help' for help\n\n";
do {
//cout << ": ";
cin >> line;
if (line == "exit"){
return 0;
}
if (line == "box"){
char buffer[100];
cout << "\nEnter the title of the messagebox: ";
cin.getline(buffer,100);
char buffertwo[100];
cout << "\nEnter the text of the messagebox: ";
cin.getline(buffertwo,100);
MessageBox(NULL, buffertwo, buffer, 0);
}
if (line == "clear"){
system("cls");
cout << "\n";
}
if (line == "pause"){
system("pause");
cout << "\n";
}
if (line == "help"){
cout << "\nBOX Used to display a simple messagebox\nExample - Box 'Title Here' 'Text Here'\nCLEAR Used to clear the console screen\nExample - clear\nEXIT Used to exit the console\nExample - exit\nHELP Used to display a list of commands\nExample - help\nPAUSE Used to pause the console \nExample - pause\nPRINT Used to echo things out into the console\nExample - print 'text here'\n";
}
if (line == "print "){
strtoktest();
}
} while (line != "exit");
cout << "Exiting...";
return 0;
}it says that line is undelared and to use this function first... now i know what that means... so i tried to put this function AFTER the int main and then main didnt know what strtoktest() meant so i put it back before main.. is there like a way, to make string line; global? (im used to autoit where you could go like: Global $variable... is there a way to do this, please ask if you do not understand what i mean... thanks ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|