console io

A

alex

i'm writing a console app using unmanaged c++ that uses cout/cin to request
a few database connection strings and read them into some string variables.
The problem is: after the frist db connection string is entered, the next
set of cout/cin statements is run thru without giving the user a chance to
input the second db connection string the app requires. I think this is
happening because the database connection strings i'm using have semi-colons
(;) in them (name-value pairs separated by semicolons). If I put in simple
strings like adsfkadsf asdflkjads, the io works as expected. I'm pretty sure
the problem is the semi-colons but don't know what to do about it. There are
also equal signs (=) and single quotes (') in the db connection strings.
Anybody know anything about this?
 
J

John Harrison

alex said:
i'm writing a console app using unmanaged c++ that uses cout/cin to request
a few database connection strings and read them into some string variables.
The problem is: after the frist db connection string is entered, the next
set of cout/cin statements is run thru without giving the user a chance to
input the second db connection string the app requires. I think this is
happening because the database connection strings i'm using have semi-colons
(;) in them (name-value pairs separated by semicolons). If I put in simple
strings like adsfkadsf asdflkjads, the io works as expected. I'm pretty sure
the problem is the semi-colons but don't know what to do about it. There are
also equal signs (=) and single quotes (') in the db connection strings.
Anybody know anything about this?

I doubt your reasoning is correct. I expect the problem is that you are
mixing numeric and string input incorrectly. That is the usual reason for
this error. But, of course, its impossible to help you fix this problem
because you neglected to post any code.

Post the code and it will get sorted out very quickly.

john
 
A

alex

Provider='sqloledb';Data Source='OKSANA\\OKSANA';Initial
Catalog='pubs';Integrated Security='SSPI';User ID=sa;Password=session99
 
J

John Harrison

alex said:
Provider='sqloledb';Data Source='OKSANA\\OKSANA';Initial
Catalog='pubs';Integrated Security='SSPI';User ID=sa;Password=session99

Well that's the input, but where's the code?

Clearly your problem isn't with mixing numeric and string input because
there isn't any numeric input above. Nevertheless its impossible to help you
with bugs in your code without seeing the code.

john
 
A

alex

after i enter my connect string in response to the first cout, the rest of
the code gets run thru with no stops

if i just enter a simple string like asdfjdasfadsd the code behaves normally

string targetConnectString, repositoryConnectString, tmpStr;

cout << "enter target connection string: ";

cin >> targetConnectString;

cout << '\n'

<< "enter repository connection string: ";

cin >> repositoryConnectString;

cout << '\n';
 
J

John Harrison

alex said:
after i enter my connect string in response to the first cout, the rest of
the code gets run thru with no stops

if i just enter a simple string like asdfjdasfadsd the code behaves normally

string targetConnectString, repositoryConnectString, tmpStr;

cout << "enter target connection string: ";

cin >> targetConnectString;

cout << '\n'

<< "enter repository connection string: ";

cin >> repositoryConnectString;

cout << '\n';

Well the problem is that you have spaces in your connection string, this

cin >> targetConnectString;

will stop reading at the first space. The next read will start where the
last one ended, which is why it doesn't stop, its still reading what you
entered last time.

If you want to read a line at a time use getline.

getline(cin, targetConnectString);
getline(cin, repositoryConnectString);

john
 
A

alex

that worked! you rule.

John Harrison said:
Well the problem is that you have spaces in your connection string, this

cin >> targetConnectString;

will stop reading at the first space. The next read will start where the
last one ended, which is why it doesn't stop, its still reading what you
entered last time.

If you want to read a line at a time use getline.

getline(cin, targetConnectString);
getline(cin, repositoryConnectString);

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top