[lug] O-Topic need C++ help......
D. Stimits
stimits at idcomm.com
Fri Apr 7 23:30:10 MDT 2000
John Starkey wrote:
>
> Sorry about the off topic but I can't find any help. I've looked for
> mailing lists specific to C++ but there are none that I can find on
> several portals and liszt.
>
> I'm doing a simple database for my fiance. I've been taking classes in
> intro C++ (I've posted egcs questions here before, if anyone remembers).
>
> Anyway. I'm using
>
> struct JobInfoType
> {
> .
> .
> .
> char jobDesc[100];
> char jobRfrl[100];
> }
>
> int main()
> {
> JobInfoType info;
>
> GetJobInfo //This is in a nested if
> }
>
> void GetJobInfo(JobInfoType& info)
> {
> .
> .
> .
> cout << endl << "Enter today's date (MM DD YYYY): ";
> cin >> infoTodayMonth >> infoTodayDay >> infoTodayYear;
> cout << endl << "Enter a short job description: ";
> cin.getline(info.jobDesc, 100, '\n');
> cout << endl << "Enter referral source: ";
> cin.getline(info.jobRfrl, 100, '\n');
> .
> .
> .
>
> The problem is that once compiled it will only wait for input for
> info.jobRfrl. It shows cout for "Enter job description" but doesn't wait
> for cin.
>
> I've tried: several online tutorials, 2 books, 3 - 4 different variations
> of the get()'s, and I've compiled it on a server in Maryland (same
> response so I know it's not g++'s fault). I'm beating my brain against the
> wall. I just need to accept blank spaces in some input (from cin and from
> fstream).
>
> For obvious reasons I didn't include all the code, I hope this is enough.
>
> Can anyone help me here or point me in a direction where I can find the
> answer.
>
> Many thanks, and once again sorry for the OT,
>
> John
>
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
Likely the problem is lack of stream flushing. End of line, newline,
so on, are probably still "in the pipe" when you get to the next input
statement. Consider after each input is accepted, running cin.sync(),
or maybe just before each call to cin is better. Consider ending cout
with flush, e.g., cout << "hello" << flush; note that if you use endl,
rather than a \n for a new line, endl is equivalent to the newline
*and* a flush, so flush wouldn't be used there. E.G:
cin.sync(); // cleans out the input stream.
cout << "Enter a something: " << flush;
cin >> myVariable;
// optionally, cin.sync() here also.
Probably the best source of info on this is the Stroustrup book, but
if you don't know to look for it, it's a pain to find.
More information about the LUG
mailing list