473,513 Members | 2,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iostream cin problem

Hi:

Hope this isn't an IDE or OS problem. I'm using VC++ v6 and using cin in
a console program. I use cin.getline() and sometimes just cin

Oh... Winders XP Pro Corp Ed. (ooohh... scary, no?) SP 1 on XP and sp4,
IIRC on VS enterprise. Really pushing the envelope here.

This program works fine if I run it from VC++, but even after doing a
release build, if I run the exe, it acts like I didn't enter a thing
when my prompt "enter number" or "enter anything" comes up and I enter a
valid number (or "anything")

It's strange. At first, the function clock() returned zero. Now that
works. I also had array corruption (array initialized in a constructor)
happening and the fix was to declare a dummy variable in the class
constructor. Ok enough horror. Here's a snippet - the problem snip du
jour (sp?), if you will:

Any idea why the cin object isn't doing it's job? Please? I did try
running it in 95 compatibility mode. It's a relatively fresh XP install,
too. And I'm carefull about what SW I install.

Thanks in advance
Mike
Aug 18 '07 #1
9 2758
On 2007-08-19 01:01, Active8 wrote:
Hi:

Hope this isn't an IDE or OS problem. I'm using VC++ v6 and using cin in
a console program. I use cin.getline() and sometimes just cin

Oh... Winders XP Pro Corp Ed. (ooohh... scary, no?) SP 1 on XP and sp4,
IIRC on VS enterprise. Really pushing the envelope here.

This program works fine if I run it from VC++, but even after doing a
release build, if I run the exe, it acts like I didn't enter a thing
when my prompt "enter number" or "enter anything" comes up and I enter a
valid number (or "anything")

It's strange. At first, the function clock() returned zero. Now that
works. I also had array corruption (array initialized in a constructor)
happening and the fix was to declare a dummy variable in the class
constructor. Ok enough horror. Here's a snippet - the problem snip du
jour (sp?), if you will:

Any idea why the cin object isn't doing it's job? Please? I did try
running it in 95 compatibility mode. It's a relatively fresh XP install,
too. And I'm carefull about what SW I install.
First off, you forgot to post the snippet, and, while it probably has
nothing to do with your problem, you really should install SP2 for XP.

--
Erik Wikström
Aug 18 '07 #2
On Aug 18, 7:13 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-08-19 01:01, Active8 wrote:
Hi:
Hope this isn't an IDE or OS problem. I'm using VC++ v6 and using cin in
a console program. I use cin.getline() and sometimes just cin
Oh... Winders XP Pro Corp Ed. (ooohh... scary, no?) SP 1 on XP and sp4,
IIRC on VS enterprise. Really pushing the envelope here.
This program works fine if I run it from VC++, but even after doing a
release build, if I run the exe, it acts like I didn't enter a thing
when my prompt "enter number" or "enter anything" comes up and I enter a
valid number (or "anything")
It's strange. At first, the function clock() returned zero. Now that
works. I also had array corruption (array initialized in a constructor)
happening and the fix was to declare a dummy variable in the class
constructor. Ok enough horror. Here's a snippet - the problem snip du
jour (sp?), if you will:
Any idea why the cin object isn't doing it's job? Please? I did try
running it in 95 compatibility mode. It's a relatively fresh XP install,
too. And I'm carefull about what SW I install.

First off, you forgot to post the snippet, and, while it probably has
nothing to do with your problem, you really should install SP2 for XP.

--
Erik Wikström

Sorry <blushand sorry for posting via google, but mozilla is sucking
ram. I thoght I saw the prob, but it should f up either wa I run the
program.

cout << "Hexagram number now enter: ";
cin >hexnum;

Yeah. It's an I Ching program.

I don't know if something is in the buffer like a white space or what.
I *seem to have better luck with cin.getline, but as I said, this crap
app does run out of VC++

Thanks for the speedy response.

If you can, could you tell me the best way to do SP2 without upgrading
all that stuff I might not need. Seems like the online upgrade
"wizard" want's to give me everything under the sun. I especially want
to keep messenger services, MSN Messenger, and Alexa far away. I also
don't want any new services set to run at startup.

Thanks again.
Mike
Aug 19 '07 #3
"Active8" <mi******@gmail.comwrote in message
news:11*********************@k79g2000hse.googlegro ups.com...
On Aug 18, 7:13 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-08-19 01:01, Active8 wrote:
Hi:
Hope this isn't an IDE or OS problem. I'm using VC++ v6 and using cin in
a console program. I use cin.getline() and sometimes just cin
Oh... Winders XP Pro Corp Ed. (ooohh... scary, no?) SP 1 on XP and sp4,
IIRC on VS enterprise. Really pushing the envelope here.
This program works fine if I run it from VC++, but even after doing a
release build, if I run the exe, it acts like I didn't enter a thing
when my prompt "enter number" or "enter anything" comes up and I enter a
valid number (or "anything")
It's strange. At first, the function clock() returned zero. Now that
works. I also had array corruption (array initialized in a constructor)
happening and the fix was to declare a dummy variable in the class
constructor. Ok enough horror. Here's a snippet - the problem snip du
jour (sp?), if you will:
Any idea why the cin object isn't doing it's job? Please? I did try
running it in 95 compatibility mode. It's a relatively fresh XP install,
too. And I'm carefull about what SW I install.

First off, you forgot to post the snippet, and, while it probably has
nothing to do with your problem, you really should install SP2 for XP.

--
Erik Wikström

Sorry <blushand sorry for posting via google, but mozilla is sucking
ram. I thoght I saw the prob, but it should f up either wa I run the
program.

cout << "Hexagram number now enter: ";
cin >hexnum;

Yeah. It's an I Ching program.

I don't know if something is in the buffer like a white space or what.
I *seem to have better luck with cin.getline, but as I said, this crap
app does run out of VC++

Thanks for the speedy response.

If you can, could you tell me the best way to do SP2 without upgrading
all that stuff I might not need. Seems like the online upgrade
"wizard" want's to give me everything under the sun. I especially want
to keep messenger services, MSN Messenger, and Alexa far away. I also
don't want any new services set to run at startup.

=====

Well, if you go to windowsupdate.microsoft.com after authenticating your
windows XP license, it will search your machine and build a list of things
it wants to instal (critical updates). You can then, if you desire, go
through that list and uncheck anything you don't want to install. However, I
would really suggest you get all the critical updates. They close a number
of security holes in XP that can leave your computer vulnerable.
Aug 19 '07 #4

Active8 <mi******@gmail.comwrote in message...
cout << "Hexagram number now enter: ";
cin >hexnum;
'cout' is not defined. 'cin' is not defined.
'operator<<' is not defined.
'hexnum' is not defined.
In other words, you have not posted enough code to determine your problem.

I'll give you an example of what the people in this NG want to see:

#include <iostream>

int main(){
int hexnum(0);
std::cout << "Hexagram number now enter: ";
std::cin >hexnum;
std::cout << "\nthe number entered: "<<hexnum<<std::endl;
// - may need if more input. (ignores next char in buffer) -
// std::cin.ignore(); // .ignore(2); skips 2 chars, etc.
// std::cin >hexnum;
return 0;
} // main()
[ note: when posting, please use spaces, not tabs, when indenting. ]

FAQ http://www.parashift.com/c++-faq-lite

--
Bob R
POVrookie
Aug 19 '07 #5
On Aug 19, 12:14 am, "BobR" <removeBadB...@worldnet.att.netwrote:
Active8 <mike....@gmail.comwrote in message...
cout << "Hexagram number now enter: ";
cin >hexnum;

'cout' is not defined. 'cin' is not defined.
'operator<<' is not defined.
'hexnum' is not defined.
In other words, you have not posted enough code to determine your problem.

I'll give you an example of what the people in this NG want to see:

#include <iostream>

int main(){
int hexnum(0);
std::cout << "Hexagram number now enter: ";
std::cin >hexnum;
std::cout << "\nthe number entered: "<<hexnum<<std::endl;
// - may need if more input. (ignores next char in buffer) -
// std::cin.ignore(); // .ignore(2); skips 2 chars, etc.
// std::cin >hexnum;
return 0;
} // main()
[ note: when posting, please use spaces, not tabs, when indenting. ]

FAQ http://www.parashift.com/c++-faq-lite

--
Bob R
POVrookie

The above example you provided is indicative of the relevant code in
my prog except I might need an ignore() (ok that didn't help.) If
something in the code after the cin is doing it, I wouldn't know where
and to post the whole prog is a lot of tabs to change. cin *does work
elsewhere. Can't run debug 'cause it only fouls up when I'm not in vc+
+ IDE. Remember the really odd thing is that it only screws up when I
run the prog "normally" i.e. not clicking "run" button in VC++? The
program flow is the same either way except the flow stops in the case
of the former 8)

Is it possible that VC++ is preventing a condition (in the stream
buffer?) from occuring?

When I enter a valid number and hit return, the cursor just goes to a
new line, nothing else happens, I can't enter anything after that ,
and have to ctrl-c kill the prog?

I'm including iostream via fstream.h and

oh what joy, not. I tried std::cin >hexnum;

error C2653: 'std' : is not a class or namespace name

Been so long since I saw that I don't remember the fix.

Using cin as opposed to std::cin couldn't have adverse effects, could
it?

Thanks for the link. Great FAQ

Hope we're not chasing a non c++ related rabbit.

Thanks
Mike

Aug 19 '07 #6

Active8 <mi******@gmail.comwrote in message...
>
When I enter a valid number and hit return, the cursor just goes to a
new line, nothing else happens, I can't enter anything after that ,
and have to ctrl-c kill the prog?

I'm including iostream via fstream.h and
That's a problem. Always specifically include the headers you need. Do NOT
depend on one header includeing another.
'fstream.h' is a 'C' header. For 'C++', do it this way:

#include <iostream>
#include <fstream// NO '.h'

If you use the 'C' headers, use the ones provided for 'C++'.

// #include <time.h>
#include <ctime>
// #include <stdlib.h>
#include <cstdlib>
.... etc.. Check your implementation, or docs, for others.
>
oh what joy, not. I tried std::cin >hexnum;

error C2653: 'std' : is not a class or namespace name
Been so long since I saw that I don't remember the fix.
#include <fstream// NO '.h' for C++
>
Using cin as opposed to std::cin couldn't have adverse effects, could
it?
It should not compile. Turn up the warning level of your compiler.

Try those 'fixes', and post back here.

--
Bob R
POVrookie
Aug 19 '07 #7
On Aug 19, 3:28 pm, "BobR" <removeBadB...@worldnet.att.netwrote:
Active8 <mike....@gmail.comwrote in message...
When I enter a valid number and hit return, the cursor just goes to a
new line, nothing else happens, I can't enter anything after that ,
and have to ctrl-c kill the prog?
<snip>
>
Using cin as opposed to std::cin couldn't have adverse effects, could
it?

It should not compile. Turn up the warning level of your compiler.
warnings do not a failed compile make IMO, but I get you.

cin (no wonder it's used alone in the first c++ book I read. The
author must have learned c first and isn't half the coder you are?
wish I had my c/c++ ref. handy)

cin did compile and still does after the header changes unless I've
another include that's now free of the inclusion guards. I'll check.

But std::cin does work now.
>
Try those 'fixes', and post back here.
Lots of warnings about stuff not in the brainbench certification

char mybits;
char operator ^ (char rhs) {return myBits ^ rhs;} // was warning prior
to the include file changes. The xor forces an implicit cast of myBits
to int, IIR[or assume]C ? Wonder why I no longer need that protection
from myself. Is the c++ include checking to make sure there's no
possibility of data loss?

I like this one from <XMEMORY>:

.... INCLUDE\xmemory(39) : warning C4100: '_P' : unreferenced formal
parameter

microsoft's own code creates warnings from an include of an include of
who knows how many included cludes (or is it "kludge"?) nah... it must
be me.

still digging but still the same prob. I'm at warn level 4, BTW was at
3. I'll conceed it's good to see the warnings up to a point maybe
turning off specific ones one is aware of and can live with.

I'll keep at it checking for the naughty includes. Thanks for
elucidating me on something I rarely touch. Just trying to get the
classes finished and have a quick tool that I can let friends try. As
soon as I get the warnings cleaned up, if the prob still exists, I'll
just use getline() and validate the input since getline() has been
nicer to me. I wasn't going to guard against all the stoopid user
tricks - let 'em crash it if they want to waste time entering
meaningless values. It'll be a windows app when it grows up. OTHOH
fixing it right saves me the effort of warning them against easter egg
hunting. They're adults but we like to play, too.

Tnx
Mike

Aug 20 '07 #8

Active8 <mi******@gmail.comwrote in message...
<snip>

I'll keep at it checking for the naughty includes. Thanks for
elucidating me on something I rarely touch. Just trying to get the
classes finished and have a quick tool that I can let friends try. As
soon as I get the warnings cleaned up, if the prob still exists, I'll
just use getline() and validate the input since getline() has been
nicer to me.
If 'getline' works (show me/us which one you are using, and how), then
std::cin should too. You most likely have something left in the buffer. Try
this after the first input:

// .....
std::cin>>MyVar;
if( std::cin.peek() == '\n' ){
std::cin.ignore(1); // clear a 'return' left in buffer.
std::cout<<"removed a return."<<std::endl;
}
if( not std::cin ){
std::cout<<"exiting."<<std::endl;
// std::terminate(); // pick one
// exit(1);
}
std::cin>>MyVar2;
// check again
// .....

An 'std::getline' removes the '\n', std::cin' leaves it in buffer.

Don't be afraid to put plenty of 'couts' in your code to test things, they
are easily removed once everything is working.
If you have lots of input, you could put the 'check' in a function:
[ just for a loose idea. ]

bool CheckCin( std::istream &in ){
if( not in ){
return false;
}
if( in.peek() == '\n' ){
in.ignore(1);
std::cout<<"removed a return."<<std::endl;
}
return true;
} // CheckCin(istream&)

// main()
std::cin>>MyVar;
if( not CheckCin( std::cin ) ){ exit(1); }
std::cin>>MyVar2;
if( not CheckCin( std::cin ) ){ exit(1); }

I wasn't going to guard against all the stoopid user
tricks - let 'em crash it if they want to waste time entering
meaningless values. It'll be a windows app when it grows up. OTHOH
fixing it right saves me the effort of warning them against easter egg
hunting. They're adults but we like to play, too.
Tnx
Mike
Well, when you get to 'windows', std::cin, std::cout, etc. won't work! <G>

--
Bob R
POVrookie
Aug 20 '07 #9
Active8 wrote:
:: On Aug 19, 3:28 pm, "BobR" <removeBadB...@worldnet.att.netwrote:
::: Active8 <mike....@gmail.comwrote in message...
:::
:::: When I enter a valid number and hit return, the cursor just goes
:::: to a new line, nothing else happens, I can't enter anything
:::: after that , and have to ctrl-c kill the prog?
:::
:: <snip>
:::
::
:::: Using cin as opposed to std::cin couldn't have adverse effects,
:::: could it?
:::
::: It should not compile. Turn up the warning level of your compiler.
::
:: warnings do not a failed compile make IMO, but I get you.
::
:: cin (no wonder it's used alone in the first c++ book I read. The
:: author must have learned c first and isn't half the coder you are?
:: wish I had my c/c++ ref. handy)
::
:: cin did compile and still does after the header changes unless I've
:: another include that's now free of the inclusion guards. I'll
:: check.
::
:: But std::cin does work now.
:::
::: Try those 'fixes', and post back here.
::
:: Lots of warnings about stuff not in the brainbench certification
::
:: char mybits;
:: char operator ^ (char rhs) {return myBits ^ rhs;} // was warning

You cannot define operators for built-in types like char. They are
predefined.
:: prior to the include file changes. The xor forces an implicit cast
:: of myBits to int, IIR[or assume]C ? Wonder why I no longer need
:: that protection from myself. Is the c++ include checking to make
:: sure there's no possibility of data loss?
::
:: I like this one from <XMEMORY>:
::
:: ... INCLUDE\xmemory(39) : warning C4100: '_P' : unreferenced formal
:: parameter
::
:: microsoft's own code creates warnings from an include of an
:: include of who knows how many included cludes (or is it "kludge"?)
:: nah... it must be me.

Yes, it's you - for using an ancient compiler. :-)

The warnings in standard headers were fixed in VS2002, that's over 5
years ago.

After you security update your OS, you might consider getting a recent
C++ compiler. Visual C++ Express, for example, has an exceptional
price/performance ratio.
Bo Persson
Aug 20 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
3821
by: ernst.stiegler | last post by:
Hello, I just want to read a whole line from a console input. What I don't understand is that I always have to press ENTER twice in order to see the line I've entered. Here's my code : ...
1
3832
by: Pradyot Dhulipala | last post by:
Hi, I am using ns2.26 with the Makefile using C++ compiler version c++ (GCC) 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk). When I use iostream.h in a simple program and compile with c++ everything works...
9
2349
by: ai | last post by:
Hi , I have an application which has to read files of size few mba nd read them into array . Since i am using STL and std namespace to avoid the error error C2872: 'ifstream' : ambiguous...
20
5487
by: Mark | last post by:
I am using gnu g++ version 3.3.2, trying a simple test to read in and then write out a large (100,000 line) text file ########################################## CSTDIO VERSION TO READ/WRITE...
2
3960
by: humble04 | last post by:
Hi, I am compiling a collection of C++ code. Most of them are using the new format #include <iostream>. I think all of them because I failed at finding out which header file uses the old format ...
7
3193
by: S. Nurbe | last post by:
Hi, probably this is a common problem but I couldn't find yet a proper solution (and I hope there is one). I have two relative complex frameworks: one uses only iostream.h the other one only...
1
4508
by: Bill Sun | last post by:
Hi, I just want to using a console application in the .net enviroment. Before the main(), I using the #include "iostream.h" but the .net tell me:...
2
7142
by: NewToCPP | last post by:
I am having some trouble including "iostream" "fstream" to my code. I tried the following ways and base times it did not work. What is the problem? test.cc: ======= ..... #include...
2
1765
by: Chris Jones | last post by:
I am using the old <iostream.h>. When I compile a simple test program that uses <iostream.h>, Visual C++ 7 gives me this strange error: Compiling... capp.cpp C:\Program Files\Microsoft Visual...
1
2117
by: lars.uffmann | last post by:
Hello everyone! I just debugged a pretty huge project, eliminating basically every memory leak that would occur with the current configuration files, at least according to the mtrace() tool from...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.