|
Hi !
If it's acceptable for you to use ANSI C++, the solution is below:
#include <fstream>
#include <string>
#include <list>using namespace std;
int main()
{
ifstream inputfile("readme.txt");
istream_iterator<string> isi(inputfile), iseof;
list<string> ls;
copy(isi, iseof, back_inserter(ls));
return 0;
}
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
becase forume eats some brackets - here is the repost... I think you know that symbols should be instead of "[" and "]"
#include [fstream]
#include [string]
#include [list]
using namespace std;
int main()
{
ifstream inputfile("readme.txt");
istream_iterator[string] isi(inputfile), iseof;
list[string] ls;
copy(isi, iseof, back_inserter(ls));
return 0;
}
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
Thanks. But I need to implement parsing in ANSI C without STL. Could any og you pass me a link to some code?
Hush..Hush.. thought I heard you calling my name now...
|
|
|
|
|
for parsing u can use strtok. u can get token string from a bigger string based on a known seperator
char *buffer; // buffer to parse
char *token; // the token string
char sep[]=" "; // here seperator is space
...
token = strtok(buffer,sep);
while(token != NULL)
{
... process token
token = (NULL,sep);
}
I hope this is what u r looking for
|
|
|
|
|
Hi all.
How can i convert char * variable to OLECHAR * variable ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hi Hadi !
Try this macro: A2OLE and take a look at "String Conversion Macros" article in MSDN.
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
I read this article, but i didn't understand !!!
Can you write an example ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hmm. Here it is :
USES_CONVERSION;
OLECHAR* pOLECHAR = A2OLE("example");
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
I got 3 errors:
error C2440: 'initializing' : cannot convert from 'int' to 'unsigned short *'
error C2065: 'A2OLE' : undeclared identifier
'USES_CONVERSION' : undeclared identifier
Are you sure i don't need with any header file ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
try #inlclude <atlconv.h>... but I'm not sure is it posssible to include this file directly ... Is your project ATL-based ?
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
My program is MFC mode.
I think wchar_t is equal with OLECHAR ...
Does i have not any other way ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
include [atlconv.h] file into your source file and try A2OLE macro.
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
Excellent ...
Thanks aloooooooot for your answers and your time.
Now, my program will work, perfectly ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Please be aware that you should NOT use OLE2A in a tight loop.
This is will propably crash:
void main()
{
USES_CONVERSION;
LPSTR sz="";
BSTR bstr = L"Goodbye, World...";
for (int i=0 ; i<100000 ; i++)
sz = OLE2A(bstr);
}
The reason is that OLE2A allocates memory on the stack for performance reasons, so you will run out of stack space if you do not take care to leave scope once in a while.
Instead, put your OLE2A macro in a separate function, where it is certain that it will not be called several times without leaving scope - or use dynamically allocated mamory (slower but safer).
Christian Skovdal Andersen
|
|
|
|
|
Just one quick comment on the ATL convertion macro's.
They alloc the string on the stack, using _alloca(), so they are no good for long strings, or when used in a loop...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Yeah, right. But there is a ocscpy() function to copy converted string into a pre-allocated memory.
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
|
|
Where do you find that function?
It's not documented anywhere in the MSDN Libaray...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Try to "Search" Tab in MSDNL. =)
ps: I've faced this function when I've been programming SnapIn.
ps2:here is the local address in my hard disk: (but I'm not sure that URL will be correctly displayed in forum):
mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN\2000OCT\1033\period99.chm::/html/VC99A01.htm
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
Found it
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hi Andres,
You A2OLE isn't good for use in long strings ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
If you use a standard stacksize and convert more than 1 mb with the ATL macro's, you get a stack overflow error, and your app. crashes...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
So, if my data was more 1 MB then i must use _alloca() ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
No, it means you should change stack size. (in linker's options)...
ps: it's a never-ending thread =)
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|