RE: anal panic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



(1) I'm not sure that "anal panic" is an appropriate subject, but, none-the-less...
(2) Get Bruce Eckel's online book at http://mindview.net/Books/DownloadSites and download the first volume of the "Thinking in C++". I'm not recommending the book not because its better/worse but because the code snippets happen to be compileable on G++ (we'll get to this in just a second). He doesn't get to actual coding until the middle of the second chapter. I'd suggest that you NOT skip the introduction, the first or the first half of the second chapters.
(3) You may want to consider an IDE to help smooth things along. Learning to program is hard enough without also having to jump the hurdles with windows, make files etc. My favorite IDE is merit-ware but not open-source (that means its free, but you should donate if you like it); email me personally if you want to know what it is.
(4) You aren't properly using the standard (std) namespace. If this means nothing to you, then reread Bruce Eckel.
(5) Your code snippet is this:
ofstream out;
out.open("testfile.txt");
out << "here is a line" << endl;
A fully compliant piece of code would look like this (for the same result):
#include <fstream> /* you must import this library */
int main ( int argc, char *argv[] ) { /* you need all these warts for the entry point, this is C++, not C! */
std::ofstream testfile("testfile.txt"); /* use the std:: namespace wart to get to the ofstream object; use the nice constructor syntax */
testfile << "Here is a line of text\n"; /* although we could use std::endl, it is NOT a character and produces a wart in a text file; use the eol character \n instead */
return 5001; /* return a value ... this doesn't matter that much at this point */
}/* remember to put an extra line at the end of your file */
 
(6) Since you're learning, I'd suggest you turn on as many warnings as you can, specifically, full compliance and pedantic (the flags are in the documentation): the warnings not only tell you where you might have problems, but they also tend to have good coding advice.
 
Good luck,
 
-j.

	-----Original Message----- 
	From: gcc-help-owner@xxxxxxxxxxx on behalf of rurik leffanta 
	Sent: Sat 1/31/2004 12:57 PM 
	To: gcc-help@xxxxxxxxxxx 
	Cc: 
	Subject: anal panic
	
	

	i apologise (sorry - i have lots of experience with being newbie)
	
	but i have to go on just to attempt to depict myself as a non-idiot person..
	(lol)
	
	i've been trynig to learn c++ from "c++ by example," by steve donovan.. it
	comes with an app called 'underc' (which is free on the web i believe) which
	allows beginners to test c++ syntax in real time w/o having to compile..
	
	unfortunately, this text has driven me completely mad with frustration over
	the last few years (yes, years) because things like
	ofstream out;
	out.open("testfile.txt");
	out << "here is a line" << endl;
	
	WORK in 'underc,' although it seems to have no relevance to 'real' c++.. so
	i've got a textbook full of apparently useless syntax, since there is no
	explanation on how to 'qualify ofstream as a type,' which is my compile
	error.
	
	moreover, the text truly is 'by example,' ie. one is generally expected to
	intuit the functionality from examples instead of a taxonomic analysis :p
	
	sigh. i promise, no more emails to list this week, so tia for any replies.
	--
	http://home.earthlink.net/~plattermatic
	http://www.panicnow.net/~xoxos
	----- Original Message -----
	From: "rurik leffanta" <plattermatic@xxxxxxxxxxxxx>
	To: <gcc-help@xxxxxxxxxxx>
	Sent: Saturday, January 31, 2004 11:40 AM
	Subject: Re: newbie! - sorry!
	
	
	> alex - thanks! sorry about that - since i've had to resort to using 1/2
	> dozen tutorials to figure out each simple step, i now had 6 different
	> conflicting sources of information..
	>
	> ..as such, following one alleged 'gcc' tutorial, i was successfully
	> compiling examples with a two stage operation:
	> gcc -c -o name.o name.c
	> gcc -mwindows -o name.exe name.o
	>
	> so i guess i was attempting to compile it as a c program as opposed to
	c++??
	> :p dumb error, i blame the tutorial :)
	>
	> i've found i can compile c++ using two different commands:
	>
	> gcc name.cpp
	> or:
	> c++ name.cpp
	>
	> (or, now add alex's g++..)
	>
	> which is great, except i have no information about what the difference is,
	> or any clue why they both work when i only have one v. of gcc, beyond i
	have
	> tutorials that say to do it each way.. curious indeed.
	>
	> i want to write my *first* program to simply create a text file and put a
	> word in it.
	>
	> can i *find* a demo program that addresses just this fundamental,
	elementary
	> function? NO! :p
	>
	> instead i've got 32 'hello world' programs, each of which are different :)
	>
	> #include <fstream>
	> ofstream out;
	> out.open("testfile.txt");
	> out << "here is a line" << endl;
	> out.close();
	>
	> look. i'm totally screwing around in the dark here. i've tried wrapping it
	> all in a 'main' function, leaving parts inside and outside, i'm aware that
	> there is no 'nice, safe,' code for checking to see whether the file
	exists.
	>
	> could somebody turn this into a nice example of how to make a program that
	> creates a text file, and one day, i'll put it all on the web in a nice
	> tutorial about how to use (install..) gcc coming from basic, in english..
	>
	> i hate asking for help :p :)
	> --
	> http://home.earthlink.net/~plattermatic
	> http://www.panicnow.net/~xoxos
	> ----- Original Message -----
	> From: "rurik leffanta" <plattermatic@xxxxxxxxxxxxx>
	> To: <gcc-help@xxxxxxxxxxx>
	> Sent: Saturday, January 31, 2004 10:22 AM
	> Subject: newbie!
	>
	>
	> > i'm attempting to write my vewy first c++ prog....
	> >
	> > in order to perform iostream operations, i have to #include <iostream>
	> >
	> > yes? yes. :p (or iostream.h, depending on tutorial..)
	> >
	> > however, 'iostream' is not at the top of my include folder. i am using
	> mingw
	> > 3.1.0-1 (and have successfully compiled example scripts) - the path for
	> > iostream with this install is include/c++/3.2.3
	> >
	> > i've tried adding the path to the include statement, putting .h at the
	end
	> > of iostream..
	> >
	> > sheesh! should i copy everything from the subfolders and put it in the
	> main
	> > folder? what do i have to do here?
	> > --
	> > http://home.earthlink.net/~plattermatic
	> > http://www.panicnow.net/~xoxos
	> >
	>
	
	



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux