Re: I'm a newb!!

From: osmium (r124c4u102_at_comcast.net)
Date: 10/16/03


Date: Thu, 16 Oct 2003 07:36:50 -0700

Ryan Giuliany writes:

> I'm trying to get a VERY simple program to take the input data and write
it
> to a text file. First of all...is this even possible with out tons of
extra
> code?
>
> Here's what I tried
>
> #include <iostream>
> #include <string>
> using namespace std;
>
> int main()
> {
> string hello;
> cout << "What is your name?\n";
> cin >> hello;
> cin.read >> "c:\teststore.txt"; // trying to make it write to a file.
> cout << "\n" << hello << "\n\n\n";
> return 0;
>
>
> }

cin and cout are rather peculiar things. They are _objects_ that have been
pre-assigned by the compiler before the compiler lets you get control of the
system. cin is normally attached, so to speak, to the keyboard and cout to
the monitor. You want output to go to a file instead of the monitor; so you
must establish your own object, as shown by one of the other posters.

Certain variables and things that are or act like constants (actually often
a _macro_) such as NULL are "pre-used". A nice list of these oddities would
be a good thing to have in a list. I have no such list.



Relevant Pages

  • Re: g++ problem
    ... start of main the g++ compiler did not recognize cin and cout. ... Add a "using namespace std;" or prefix each cin and cout with the ...
    (Debian-User)
  • Re: g++ problem
    ... Although #include <iostream> was entered before the ... start of main the g++ compiler did not recognize cin and cout. ...
    (Debian-User)
  • Re: C# syntax as an option in Delphi w32
    ... monitor the Objects lifecycle. ... Each native executable has it's own heap manager, ... which are the main reason why a C++ compiler has to ... faster than heap allocations in native applications and you the GC heap ...
    (borland.public.delphi.non-technical)
  • Re: screen resolution
    ... I would not suppose the compiler was amiss again. ... Identifier "Screen0" ... Monitor "Monitor0" ... VendorName "Monitor Vendor" ...
    (Fedora)
  • Re: C++: Redirecting stdin & stdout to same file with freopen
    ... use cin to read from that file and cout to write to it. ... to simply have my test code redirect stdin/stdout to a common file. ...
    (microsoft.public.vc.language)