Plugin Help C++ opening file - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: WLM Plus! Help (/forumdisplay.php?fid=12)
+----- Thread: Plugin Help C++ opening file (/showthread.php?tid=29859)
Plugin Help C++ opening file by crank on 08-12-2004 at 02:02 PM
I'm working at QTSender during my spare time(when i'm not fixing MSNBrowser).
I found a code for a file but I can't make it really work.
Headers:
code: #include <fstream.h>
#include <iostream.h>
Code:
code:
char str[1100]; //set string lenght
int nRandom = rand()%3;
if(nRandom == 0)
ifstream b_file("QTS1.txt");//opens file for reading
b_file>>str; //reads one string from file
strcpy(sResult, str); //output text
b_file.close();//close file
Build/Debug Log:
code: MPPluginC.cpp
c:\documents and settings\kenneth\mijn documenten\msgplus!plugin source\qts(openfiletest)\vc\mppluginc\mppluginc.cpp(96) : error C2065: 'b_file' : undeclared identifier
c:\documents and settings\kenneth\mijn documenten\msgplus!plugin source\qts(openfiletest)\vc\mppluginc\mppluginc.cpp(96) : error C2297: '>>' : illegal, right operand has type 'char [1100]'
c:\documents and settings\kenneth\mijn documenten\msgplus!plugin source\qts(openfiletest)\vc\mppluginc\mppluginc.cpp(98) : error C2228: left of '.close' must have class/struct/union type
c:\documents and settings\kenneth\mijn documenten\msgplus!plugin source\qts(openfiletest)\vc\mppluginc\mppluginc.cpp(102) : error C2297: '>>' : illegal, right operand has type 'char [1100]'
c:\documents and settings\kenneth\mijn documenten\msgplus!plugin source\qts(openfiletest)\vc\mppluginc\mppluginc.cpp(104) : error C2228: left of '.close' must have class/struct/union type
c:\documents and settings\kenneth\mijn documenten\msgplus!plugin source\qts(openfiletest)\vc\mppluginc\mppluginc.cpp(106) : error C2181: illegal else without matching if
Error executing cl.exe.
MPPluginC.obj - 6 error(s), 0 warning(s)
(If you copy this to notepad it will be easier to read)
My question is how to fix those errors???
Or is the code to open the file wrong???
What should i change the >> too???
I know most of these are 'beginner' faults but i just can't work with files in C++
Fixed some stuff myself (the bold stuff)
RE: Plugin Help C++ opening file by RaceProUK on 08-13-2004 at 09:51 AM
code: if(nRandom == 0) {
ifstream b_file("QTS1.txt");
b_file>>str;
strcpy(sResult, str);
b_file.close();
}
Same code, with added bracyness. That should clear a lot of the errors you're having, if not all.
RE: Plugin Help C++ opening file by crank on 08-13-2004 at 05:23 PM
I'll try that
EDIT:Woohooow woohooow SUPER!!!!
It worked
EDIT2:
The only thing wrong is that the thing ouputs Ì 1100 times instead of the text in the file.
RE: Plugin Help C++ opening file by RaceProUK on 08-13-2004 at 06:53 PM
str is a char variable? If so, that's why. You'll have to write code that can read whole strings instead.
I recommend you get a book on C++: it will tell you all you need to know. I recommend Sam's Teach Yourself C++ in 21 Days.
RE: Plugin Help C++ opening file by crank on 08-17-2004 at 01:35 PM
I'm looking for a book on C++ but It has to be dutch...
RE: Plugin Help C++ opening file by Tochjo on 08-17-2004 at 01:40 PM
quote: Originally posted by çr@nK
I'm looking for a book on C++ but It has to be dutch...
Bol.com > Netherlands > Boeken (Nederlands)/Books (Dutch): C++
|