|
I have files with the format:
number, "words", "words", "words", numbers
number, "words", "words", "words", numbers
etc...
I need to read each individual thing( number or "words") in between the commas. I originally checked each caracter to see if it was a comma. If it wasn't I added it to a string then got the next character. If it was a comma then I have my the thing between the commas. This arose two problems. (1)I can't get spaces because I'm reading the file using ifstream. (2)There can be commas in "words" thus ending the string before I read the complete string.
My solution(I dont like it): Because all "words" are surrounded in quotes I could check to find if it has reached the real comma, which i think would add a lot more code But this still doesn't fix the spaces problem. Should I drop the ifstream and use another file reading meathod( I don't know of any)?
[edit]
Oh yeah, the number does not need to be read as a number, it can be read as a string/char.
-Raffi
|
|
|
|
|
Use a tokenizer like <a href="http://boost.org/libs/tokenizer/index.htm">boost:tokenizer</a> . It seems a little overwhelming at first, but comes equipped with a predefined setting for exactly the kind of thing you want to do (check <a href="http://boost.org/libs/tokenizer/escaped_list_separator.htm">escaped_list_separator</a> .)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
iostreams is made for this.
ifstream f ("c:\\myfile.txt");
int n;
string a, b, c;
f >> n >> "," >> a >> "," >> b >> "," >> c;
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
I think iostream s won't handle strings enclosed in quotes.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Oh. I don't know about that, but I took the quotes to mean 'this is a string', not 'this is a string in quotes'
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Even assuming the format is very well behaved, iostream s won't work. Consider for instance:
5, "hello", "my", "friends", 10 The first "word" read would be "hello", (comma included), as it is only white space that will stop the stream reading a token.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks a lot.
-Raffi
|
|
|
|
|
Hi every one,
I meet a trouble.
When i installed my applicaiton on a clean win2k. It terminated every time when it execute:
"pws->Create(wsName, UserName,"");" ,
pws is a CDaoWorkspace object.
But after I installed the "Application Performance Explorer" in "Visual Stutio Enterprise tools" on this platform, then My application works well.
What is the different after I install the tool?
What should I do in my installation?
|
|
|
|
|
You got a new set of dlls. One or more of them was different. If you want to move this program to other machines, you will need to find out which one. Use the DEPENDS.EXE program that ships with Visual Studio to get a list of the dlls your program uses. Then look at the versions and dates. Compare them with what is on a "clean" system. You will see a differnece.
Hope the helps,
Bill
|
|
|
|
|
I'm created MDI app without Doc/View suppot.
The name of MDIChild window stored in string table resourse "\nTitle\n".
When I open child wnd, the title of app window is "App - Title" and when I maximise child window "App - Title - [Title]", how can I remove one "Title" from window title?
Anything that can go wrong will go wrong.
|
|
|
|
|
Remove the FWS_ADDTOTITLE style
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
Pleas help! I know nothing about Databases
I have an MFC Dialog app that connects to a Access database. I found some great code here www.codeproject.com/database/readdb.asp and this works fine but it only shows how to read from a database. I need to send data to the database from my dialog app as well as read. If anyone knows how to do this using the same structure as in this demo I would be really really grateful!
Thanks,
Alan
|
|
|
|
|
How about this article?
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hello all,
does anyone have any experience with MS Flex Grid?
I want a simple, MS based, lightweight grid control that allows me to:
- display tabular data
- sort (numerical, dates, string)
- dispaly boolean values (checkbox)
- edit the data
- Show cell focus selection
There is a lot of great information on how to customize the standard MS
list control, but was wondering if MS Flex Grid can be used instead.
If someone knows about a good documentation, please let me know.
thanks
|
|
|
|
|
With the exception of the checkbox, MSFlexGrid will do all of those things. It might even do the checkbox, I've never tried it.
Hope this helps,
Bill
|
|
|
|
|
Maybe a simple question for the most of you...
How can I force to open a menu in a menubar without using the mouse?
I´ve tried this...
RECT rect;
int nCnt = 0;
::GetMenuItemRect(hWnd,hMenu,nCnt,&rect);
::SendMessage(hWnd,
WM_LBUTTONDOWN,
(WPARAM)MK_LBUTTON,
MAKELPARAM(LOWORD(rect.left),HIWORD(rect.top)));
This should open the very first menu in the menubar (typically "File" menu), but it doesn´t work...
Any ideas?
Amar
|
|
|
|
|
You should look up the TrackPopupMenu API call.
Regards
Nish
The rumours that I am an AI bot are absolutely false. These rumours have been propogated by *them* to focus all the attention on to me, while *their* bots take over the planet. Thank y%%%% Divide by zero. Cannot proceed. Abort(y/y)?
|
|
|
|
|
Hi,
How to calculate the date and time in different timezones? How to convert a specific Standard Time to localtime in different timezones? With localtime API we will be able to do that for current timezone settings. But if we want to find out the localtime for different timezones (e.g. EST, Pasific, Mountain etc..), is there a way to achieve that?
Amar
|
|
|
|
|
Get this from MSDN:
if( _putenv( "TZ=EST5EDT" ) == -1 )
{
printf( "Unable to set TZ\n" );
exit( 1 );
}
else
{
_tzset();
printf( "_daylight = %d\n", _daylight );
printf( "_timezone = %ld\n", _timezone );
printf( "_tzname[0] = %s\n", _tzname[0] );
}
|
|
|
|
|
I am very puzzled by this one. Previously, when one wanted to have a custom enum in the typelib, he simply put it in the library section of the idl file:
library SomeLib
{
typedef enum { someval } MyEnum;
}
and voila.
But with VC.NET, and attributed C++, how do you do that??? I tried the following:
[module .....];
[export, public]
typedef enum { someval } MyEnum;
but the declaration is not part of the typelib, since it is before the library statement in the generated idl file.
Anyone have tried this before? Is it still possible to do it? Do I have to switch back to non-attributed C++???
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Hi all,
I wish to malloc a large char array (to handle appr. 1 MB file sizes), how can I do that without cracking my computer wide open?
/Tommy
|
|
|
|
|
If you absolutely need to have a contiguous block of memory of 1MB, go ahead and request to malloc a block that big. Chances are there'll be no serious problems, as 1MB is handlable by PCs these days, and moreover the virtual paging mechanism will help liven things up.
Apart from this, maybe you can get by with some block of memory that grows on demand, so that only gets to these huge sizes when actually required. If so, have a look at std::vector , which automates this behavior for you.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquin is right!
Better allocate the memory as you need it:
with malloc and realloc I normally use! So you don't have to allocate on 1MB up front!
Al
|
|
|
|
|
Malloc will work just fine with one warning.
The only problem I have ever run into with allocating large blocks of memory is that if you allocate/free that block a lot, you run the risk of fragmenting your virtual address space. This can happen if you free that 1MB block and then part of it is used by a smaller allocation. Then when you go and try to allocate 1MB again, the system has to allocate a new 1MB block.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Have you considered memory mapping the file? Not only is this faster than reading the file into a buffer, but it will be read into memory on demand (as you access the different parts of the file).
Chris
|
|
|
|
|