Complete Noob. Reading/Writing to/from Textfile

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 2
Reputation: noobyjoe is an unknown quantity at this point 
Solved Threads: 0
noobyjoe noobyjoe is offline Offline
Newbie Poster

Complete Noob. Reading/Writing to/from Textfile

 
0
  #1
Nov 7th, 2007
Hi There,

It is my first post. I am currently workign for a company and have just been moved into R+D. Part of my new job involves C++ Programming.

I am having trouble with numerous things, (was thrown in the deepend)
Basically, This program is designed to keep track of all surfacemounth component activity, jobs, reference numbers, part locations etc...

The thing i am having trouble with is this...
Every PCB has a specific lay file which basically shows all the different components and their quantities taken from the stores location.

This new addition to the program I am working on will enable each tube/reel of parts to be given a new unique reference assignment.

I am having trouble trying to figure out how to read the specific reference number "06/11/07_1" so that the "1" will become an integer and can be incremented everytime there is a new reference number, and also that the program has intelligence as to what was the last reference number given so that it continues from where it left off.

Sorry if my gobble-dee-gook is confusing, but i was trying to put it in the best way i could.

If anyone can help a noob, i would greatly appreciate it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,448
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1475
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Complete Noob. Reading/Writing to/from Textfile

 
0
  #2
Nov 7th, 2007
If the program knows the last number used, such as "06/11/07_1", then extract the digits beyond the underline, convert to int, increment the int, then reformat the number.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 7
Reputation: Gadgetman_53 is an unknown quantity at this point 
Solved Threads: 0
Gadgetman_53 Gadgetman_53 is offline Offline
Newbie Poster

Re: Complete Noob. Reading/Writing to/from Textfile

 
0
  #3
Nov 7th, 2007
Try something like this, I'm still new to C++, but learning. Hope this works.

  1. int month;
  2. int date;
  3. int year;
  4. int someint;
  5.  
  6. InFile >> month;
  7. InFile.ignore(500, '/');
  8. InFile >> day;
  9. InFile.ignore(500,'/');
  10. InFile >> year;
  11. InFile.ignore(500, '_');
  12. InFile >> someint;
  13. //InFile is declared as the ifstream
Last edited by Gadgetman_53; Nov 7th, 2007 at 12:52 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Complete Noob. Reading/Writing to/from Textfile

 
0
  #4
Nov 7th, 2007
>If anyone can help a noob, i would greatly appreciate it

Showing us what code you have so far might be an idea hey!?
Last edited by iamthwee; Nov 7th, 2007 at 2:02 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Complete Noob. Reading/Writing to/from Textfile

 
0
  #5
Nov 7th, 2007
one way to implement dragon's algorithm:
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std ;
  4.  
  5. enum { delimiter = '_' } ;
  6.  
  7. int digits_beyond_delimiter( const string& str )
  8. {
  9. istringstream stm(str) ;
  10. if( stm.ignore( str.size(), '_' ) )
  11. {
  12. int number ;
  13. if( stm >> number ) return number ;
  14. }
  15. return -1 ; // error in string
  16. }
  17.  
  18. string replace_number_after_delimiter( const string& str, int number )
  19. {
  20. istringstream input( str ) ;
  21. ostringstream output ;
  22. char ch ;
  23. while( input.get(ch) )
  24. {
  25. output.put(ch) ;
  26. if( ch == delimiter ) break ;
  27. }
  28. output << number ;
  29. return output.str() ;
  30. }
  31.  
  32.  
  33. int main()
  34. {
  35. const string str = "06/11/07_13" ;
  36. int number = digits_beyond_delimiter( str ) ;
  37. cout << str << '\n' ;
  38. string result = replace_number_after_delimiter( str, ++number ) ;
  39. cout << result << '\n' ;
  40. }
Last edited by vijayan121; Nov 7th, 2007 at 2:40 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Complete Noob. Reading/Writing to/from Textfile

 
0
  #6
Nov 7th, 2007
My advice would be to put the problem aside for a month and get some basic C++ under your belt first. Look for a book called "Accelerated C++".

Hacking away at the problem one post at a time on a forum isn't going to produce a meaningful product at the end of it, and isn't going to be done any quicker either.

From what you've said, it sounds like you're modifying a rather extensive existing program, in which case your newbie-ish hackery is just going to be a future maintenance nightmare.

That is assuming your employer knows that you don't know C++, and will understand your request for learning time. If on the other hand you claimed some C++ skill and they've called your bluff, well then that's your problem to deal with. Using a forum to get others to do your job for free isn't the way to go.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2
Reputation: noobyjoe is an unknown quantity at this point 
Solved Threads: 0
noobyjoe noobyjoe is offline Offline
Newbie Poster

Re: Complete Noob. Reading/Writing to/from Textfile

 
0
  #7
Nov 8th, 2007
Originally Posted by Salem View Post
My advice would be to put the problem aside for a month and get some basic C++ under your belt first. Look for a book called "Accelerated C++".

Hacking away at the problem one post at a time on a forum isn't going to produce a meaningful product at the end of it, and isn't going to be done any quicker either.

From what you've said, it sounds like you're modifying a rather extensive existing program, in which case your newbie-ish hackery is just going to be a future maintenance nightmare.

That is assuming your employer knows that you don't know C++, and will understand your request for learning time. If on the other hand you claimed some C++ skill and they've called your bluff, well then that's your problem to deal with. Using a forum to get others to do your job for free isn't the way to go.


Yes you are right, I am a newb, however the company does know this.. Currently studying a degree in electronics in my spare time, and we havent really gotten into depths of c++ in the course (not to mention the course is distance learning and is done in my spare time) I have been hacking away at this and a few other things like automated testing procedures(these of which aren't that bad - mainly because i see what was done in the previous ones).
I have that sam's tech yourself c++ in 21 days, is that c++ accelerated book any decent?



Anyways, the code i have thus far for where i need this to go is...



//---------------------------------------------------------------------------
void __fastcall TStockTransferForm::Button2Click(TObject *Sender)
{
TListItem *aListItem2;
TQuery *aQuery = NULL;
TQuery *aQuery2 = NULL;
AnsiString asType, asStr;
AnsiString asPartnum, asQuantity, asRefnum;
//int iRef to be the incrementing integer..


TransferListView->Items->Clear();

aQuery2 = new TQuery( NULL ); //query to find partcode, and also SM Feeder type
aQuery2->DatabaseName = DataModuleForm->AutoQDatabase->DatabaseName;
aQuery2->SQL->Add( "select * from aq_part join aq_footprint on aq_part.part_ftprintcode = aq_footprint.ftprintcode where aq_part.partcode = :p0" );

aQuery = new TQuery( NULL ); //query to find reference layfile code
aQuery->DatabaseName = DataModuleForm->EfacsDatabase->DatabaseName;
aQuery->SQL->Add( "select * from transact where tratype = 'MTP' and traloc = 'SM-Q' and trasource = 'RLS' and traref = :p0 order by trapart asc " );

asStr = "PRO";
asStr += AnsiString:tringOfChar('0', 6-ReferenceEdit->Text.Length());
asStr += ReferenceEdit->Text;
aQuery->Params->Items[0]->AsString = asStr;
aQuery->Open();
aQuery->First();
for ( int i=0 ; i<aQuery->RecordCount ; i++ )
{
aListItem2 = TransferListView->Items->Add();
aListItem2->Caption = aQuery->FieldValues["trapart"];
aListItem2->SubItems->Add( aQuery->FieldValues[ "TRAQUANT" ] );

aQuery2->Params->Items[0]->AsString = aQuery->FieldValues["trapart"];
aQuery2->Open();
aQuery2->First();

if ( aQuery2->RecordCount )
{
aListItem2->SubItems->Add( aQuery2->FieldValues[ "FTPRINTTYPE" ] );
}
else
{
aListItem2->SubItems->Add( "NA" );
}
aListItem2->SubItems->Add( 1 );
aQuery->Next();


asPartnum = aQuery->FieldValues[ "trapart" ];
asQuantity = aQuery->FieldValues[ "TRAQUANT" ];


asRefnum = DateToStr(Date()) + "_" + iRef;
TransferStrings->Lines->Add( asPartnum + ", " + asQuantity + ", " + asRefnum );

}
delete aQuery;
delete aQuery2;
}




Tis a bunch of SQL and database stuff as you can "c"...Tbh, i know "mimmicking isn't the best way as you don't really learn the theory behind everything, but i think i have done pretty well so far.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC