Problem With Vc++


Recommended Posts

ok I ran into a problem moving a program over to Vc++ to make sure it ran before sending in for home work.

the line

cout << s << flush;

from my function

int promptUser (const string& s)

{

while (true) {

int user_input;

cout << s << flush;

cin >> user_input;

if (cin.fail()) {

cerr << "invalid input \n";

cin.clear();

cin.ignore();

}

else

return user_input;

}

}

throws an error.

I had to change it to

cout << s.cstr();

to make it work..

any guesses on this one?

thanks..

I was banging my head aginst the wall as VC++ does not tell you where the error occured.. I think they want you to guess??

at least with Dev-c++ ane Gcc it says

array.cpp:34

where 34 is the line number

Link to post
Share on other sites

Huh. It builds and runs fine with both gcc -std=c++98 -pedantic and icc -strict_ansi. It should be fine unless both compilers are broken.

I'll add this to the list of things to check in the standard.

Edit: Does it work if you change that line to

cout << s;
cout.flush();

?

Edited by jcl
Link to post
Share on other sites

Vc++ (visual C++)

still throws an error..

Gcc never had a problem wiht it.. or the Borland or Intel Compiler..

It's only Vc++

Link to post
Share on other sites

Not sure what could be wrong. You might try to produce a minimal test case. Slice code out of the program until it starts working or you've reduced it to a single expression.

Edit: Just to be clear, is it a compile-time or run-time error?

Edited by jcl
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...