|
It is currently Mon May 13, 2024 2:50 am
|
Author |
Message |
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
I hate Flamin' Fist's pansies. They almost allways miss ... well Freddie, old buddy, maybe you'll once take from me a good fisting lecture you ever dreamed of
What to say Satis, imo - C++ rocks. If you put here some of your doubts, maybe you'll receive the solutions of them.
_________________ ++
|
Thu May 26, 2005 10:44 am |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16650 Location: On a slope
|
nah, I'm sure I just lack the knowledge so far. My two major complaints right now:
1. I can grab environment variables.
char * thevar = getenv("homepath");
but it puts it in a char. I don't know how to easily manipulate chars. A string is great to manipulate.
thevar = thevar + " " + "whatever the hell I want" + anothervar;
can't do that with a char. I know there are some concat functions and whatnot, but they're really limited. And I don't know how to convert from char to string.
2. switch case and strings.....
they don't work! how irritating:
ie
Either I'm doing somethign wrong/misreading error message, or swtich/case can only use single char or integer inputs.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Thu May 26, 2005 11:14 am |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
It was your 4200th post.
1. Really don't see a problem.
2. Lol, yup that won't work. Why you wouldn't try this: or just this
Anyway, in ANSI/ISO C++ anything (so break as well) after return is actionless.
_________________ ++
|
Thu May 26, 2005 11:34 am |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16650 Location: On a slope
|
as for the error message thing...
it'd just be nice to be able to define the full text of the error message at the time I create the error exception. I can easily make up cryptic numeric error codes and be done with it, but the whole going back and cross-referencing error codes with their meanings is a pain in the ass I try to avoid. AT this point, the program's small, so it's no big deal. I'm speaking more from my php experience.
Anyway, the enum thing looks promising, though it would still require me to define my error message separate from where I actually cause it. Bleh, anyway, better than an error code.
As for the environment thing, the big reason for the pain in the ass is that I don't know how to take a char and easily use it for other stuff. something along these lines is what I'm really shooting for.
char * thepath = getenv("homepath");
thepath = thepath + "local settings\temp";
execution = "net send " + destination + " " + message + " > \"" + thepath + "temporary.dat\"";
system(execution);
ie, I'm trying to grab the homedirectory environment variable so I can write my temporary file into the current user's temporary directory, where it belongs, rather than the root directory of the drive. Since the path gets stored in a char, I can't easily concatenate additional strings to the end of it. Also, you can't run the system() command on a char, it has to be a string. So even if I managed to concat all the extra crap I needed onto the char, I couldn't use it in the system function. Hence why I'm starting to hate char.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Thu May 26, 2005 12:36 pm |
|
|
derf
Minor Diety
Joined: Fri Apr 11, 2003 2:17 pm Posts: 7721 Location: Centre of the sun
|
I really think we should stop the fisting comments.
_________________ "Well a very, very hevate, ah, heavy duh burtation tonight. We had a very derrist derrison, bite, let's go ahead and terrist teysond those fullabit who have the pit." - Serene Branson
|
Thu May 26, 2005 1:13 pm |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
Tip: If you wish it to print "" you should name it "";
Have you seen how work throw - catch syntax? You can use enum in start, but later you'd wish to use whole objects. If you don't wish some extra efficiency, of course. But, then, why not to try Java?
The other: what about this?
Anyway, it is awfuly slow. A bit faster? It is better but still not fast enough. Well, we're going to limit the length of the message to, ... to, ... about N chars. I know the result is crap since I don't know to use the "net send" but who cares. Can it be better? It can, but leave it for now so. It is enough. Now we can shape it in one class (which is the point of C++ wtf). | | | | Code: #include <iostream> #include <string> using namespace std;
#include <string.h>
unsigned int strl(const char *);
class messenger {
public: messenger(unsigned int len): hpath( getenv("homepath") ),buffer(0),len(len)
{ init(); }
messenger(unsigned int len,const string&destination): hpath( getenv("homepath") ), dest(destination), buffer(0), len(len) { init(); }
~messenger() { delete [] buffer; }
void sendamessage(const string&); void setdestination(const string&);
private: unsigned int len, start; char * buffer; const char * hpath; string dest;
void init(); messenger& operator=(const messenger&); messenger(const &messenger); };
void messenger::init() { buffer = new char[ strl(hpath) + len + 47 + 1 + dest.length() ]; *buffer = 0; strcat(buffer,"net send "); start = 9;
strcat(buffer+start,dest.c_str()); start += dest.length();
strcat(buffer+start," "); start += 1; }
void messenger::sendamessage(const string& message) { char * buff = buffer + start;
strcat(buff,message.c_str()); buff += message.length();
strcat(buff," > ""); buff += 4;
strcat(buff,"local settings\\temp\\temporary.dat"");
cout << buffer; }
void messenger::setdestination(const string&newdest) { if(dest != newdest) { dest = newdest; init(); } }
main() { messenger f(500,"GFreeman");
f.sendamessage("hehe"); cout << endl;
f.setdestination("Derf"); f.sendamessage("hihi"); return 0; }
unsigned int strl(const char * a) { const char * b = a; while(*b) b++; return b - a; } | | | | |
I know I should offer some explainations with these codes but let it for later.
_________________ ++
|
Thu May 26, 2005 3:13 pm |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
Well, let forget the last two for now. I'm awfuly tired now.
_________________ ++
|
Thu May 26, 2005 3:31 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16650 Location: On a slope
|
lol, I understood some of that. I'll have to reread it when I'm not so tired.
btw, the getenv has to be a char, hence my problems. I can make the rest happen otherwise. Though I don't understand objects yet. Nor what this 'speed' thing you talk of is.
ie, I would LIKE it to be string thepath = getenv("homepath");
but it has to be char * thepath = getenv("homepath");, which blows since char is such a bitch to work with.
another point, (and I haven't even touched on this yet), is that homepath returns a full system path, it
thepath = "\documents and settings\satis"
which means I would have to parse the path and add in some extra \ to escape the existing \ before running it through a command string. Not sure how to do that, but I'm sure it's possible. IE, some command string to convert it to
thepath = "\\documents and settings]\\satis"
bleh, anyway, my head is starting to hurt.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Thu May 26, 2005 4:01 pm |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
I'm not sure I understand your request. Will take a look later, if someone other don't answer.
So, every strnig object has a mathod .c_str() which gives the null-terminated char with content of the string. If you need your commands to be chars only because of int system(const char*) command, then it can solve your prob.
_________________ ++
|
Thu May 26, 2005 4:16 pm |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
Yes. We should start with the deeds.
_________________ ++
|
Fri May 27, 2005 6:28 am |
|
|
derf
Minor Diety
Joined: Fri Apr 11, 2003 2:17 pm Posts: 7721 Location: Centre of the sun
|
the deeds?
_________________ "Well a very, very hevate, ah, heavy duh burtation tonight. We had a very derrist derrison, bite, let's go ahead and terrist teysond those fullabit who have the pit." - Serene Branson
|
Fri May 27, 2005 7:36 am |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
The fisting, dear. Quit talking. Let see how it really works. Well, program can be more efficient (need less time to be executed) and less efficient (need more time to be executed). Using operator+ on strings is awfuly more slower than using operator+=. Cos a+b will make one absolutely new string (who is unnamed by you, but it exist). a+b+c will firstly make one unnamed from a+b and then from this unnamed and c will make the another one unnamed. So if you wish to add n strings, in fact you'll have n-1 absolutely new unnamed strings made, before you get the result. The operator+= is a much better cos it don't make new objects. It is just supposed to add the new string to the current. It is a bit better - but more compliceted to write. For example: Do the same thing but the second is more efficient. Brackets in the second are necessary cos of priprity. Otherwise, you could get the unexpected results. Well, this can e useful for you as well: Here is in fact called the c_str() of the final unnamed object. At end - there is using the pure char and null-terminated strings which can be a bit more efficient, but it is more advanced. Everything depend on what you wish to do.
Do it, Sat. It will work just fine. Array of chars from getenv will be accepted as an argument for the constructor of string object. It this DOT'T WORK for you, then change the compiler. What do you use anyway?
_________________ ++
|
Fri May 27, 2005 8:15 am |
|
|
derf
Minor Diety
Joined: Fri Apr 11, 2003 2:17 pm Posts: 7721 Location: Centre of the sun
|
_________________ "Well a very, very hevate, ah, heavy duh burtation tonight. We had a very derrist derrison, bite, let's go ahead and terrist teysond those fullabit who have the pit." - Serene Branson
|
Fri May 27, 2005 11:53 am |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16650 Location: On a slope
|
lol, that's an hilarious pic.
Gfree...yea, string * blah = getenc("homepath");
doesn't work. The compiler is gcc. I'm using dev-c++ as my IDE, because it's free. I prefer an IDE over a text editor because I don't have to deal with all the crazy linking compiling whatever crap you'd have to do otherwise. Not to mention the crazy command lines.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Fri May 27, 2005 12:36 pm |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
@Satis
not
I use Borland's C++ Compiler 5.5. It is free, it is ANSI/ISO and it is widely used for schooling purposes, as I know.
http://www.borland.com/products/downloa ... ilder.html
You need JUST compiler.
_________________ ++
|
Fri May 27, 2005 1:04 pm |
|
|
Who is online |
Users browsing this forum: No registered users and 0 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|