|
-
Feb 24th, 2002, 03:49 PM
#1
Thread Starter
Addicted Member
-
Feb 24th, 2002, 04:55 PM
#2
Monday Morning Lunatic
Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string x = "Hello";
string y = "World";
string combo = string("I say: ") + x + " " + y;
cout << combo << "!" << endl;
return 0;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2002, 07:33 PM
#3
Thread Starter
Addicted Member
That worked just fine, can you tell me why my code produces errors???
Code:
#include <fstream.h>
#include <string>
using namespace std;
int main() {
string flnm, str; char ch; int i = 0;
cout << "Enter the file name..." << endl;
cin >> flnm;
cout << endl << endl;
ifstream XDEF(flnm);
while( XDEF.get(ch) ) {
str += ch;
}
cout << str << endl;
return 0;
}
Last edited by Virtual24; Feb 24th, 2002 at 07:44 PM.
To protect time is to protect everything...
-
Feb 25th, 2002, 11:11 AM
#4
Never mix the headers with .h with those without:
#include <fstream>
#include <string>
#include <iostream> // you need this for cin and cout
...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 25th, 2002, 04:36 PM
#5
Thread Starter
Addicted Member
2 things, 1, if i include the fstream.h file in my program, i dont need to include iostream b/c it does it automatically, and 2, I thought <fstream.h> and <fstream> was the same thing, isnt it?
To protect time is to protect everything...
-
Feb 25th, 2002, 06:01 PM
#6
Monday Morning Lunatic
1. Theoretically, yes. Practically, possibly not so it's safest to include what you need. Stick to the non-dot-h headers, it's better that way.
2. The .h is the old version, the other is the newer templated version that fits in with the rest of the standard library. Use it for now, and you'll find out why it's useful when you get onto templates and generic programming
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 25th, 2002, 06:12 PM
#7
transcendental analytic
I never got into the habit of .h and .cpp, as I never made something that doesn't have anything to with templates
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|