| | |
Complete Noob. Reading/Writing to/from Textfile
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Nov 2007
Posts: 7
Reputation:
Solved Threads: 0
Try something like this, I'm still new to C++, but learning. Hope this works.
C++ Syntax (Toggle Plain Text)
int month; int date; int year; int someint; InFile >> month; InFile.ignore(500, '/'); InFile >> day; InFile.ignore(500,'/'); InFile >> year; InFile.ignore(500, '_'); InFile >> someint; //InFile is declared as the ifstream
Last edited by Gadgetman_53; Nov 7th, 2007 at 12:52 pm.
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
one way to implement dragon's algorithm:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <sstream> using namespace std ; enum { delimiter = '_' } ; int digits_beyond_delimiter( const string& str ) { istringstream stm(str) ; if( stm.ignore( str.size(), '_' ) ) { int number ; if( stm >> number ) return number ; } return -1 ; // error in string } string replace_number_after_delimiter( const string& str, int number ) { istringstream input( str ) ; ostringstream output ; char ch ; while( input.get(ch) ) { output.put(ch) ; if( ch == delimiter ) break ; } output << number ; return output.str() ; } int main() { const string str = "06/11/07_13" ; int number = digits_beyond_delimiter( str ) ; cout << str << '\n' ; string result = replace_number_after_delimiter( str, ++number ) ; cout << result << '\n' ; }
Last edited by vijayan121; Nov 7th, 2007 at 2:40 pm.
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.
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.
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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.
![]() |
Similar Threads
- Send data on a serial port (C++)
- Reading or writing a double into a bin file (C++)
- i need help (Java)
- Reading and Writing Data to a File (Visual Basic 4 / 5 / 6)
- Reading binary data from a file and writing it (Visual Basic 4 / 5 / 6)
- Reading/Writing to Executable (C++)
- Need help with my console database app, program reading or writing incorrectly (C++)
- confused how to begin this program (C++)
- Read and writing strings from structures (C++)
Other Threads in the C++ Forum
- Previous Thread: can a class grant access to a friend method of friend class?
- Next Thread: A tragicomic party (plz help me)
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






