what's wrong with it ?Code:void main() { ifstream fin_noindex("noindex.txt"); ifstream fin_f1("file1.txt"); string s; if(fin_noindex.is_open() && fin_f1.is_open()) { while(fin_f1.good()) { fin_f1 >> s; cout << s << endl; } } }
what's wrong with it ?Code:void main() { ifstream fin_noindex("noindex.txt"); ifstream fin_f1("file1.txt"); string s; if(fin_noindex.is_open() && fin_f1.is_open()) { while(fin_f1.good()) { fin_f1 >> s; cout << s << endl; } } }
what exactly are you trying to do?
are you sure you have all the namespaces right?
is "while(fin_f1.good())" an infinite loop the way you put it (I've never used .good() and .is_open())
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
Well,
is one thing. main always returns an int.Code:void main()
As to what else is wrong... It would be helpful to know what problems you are having with it.
--------------------Configuration: assignment1 - Win32 Debug--------------------
Compiling...
assignment1.cpp
C:\Documents and Settings\genesis\Desktop\assignment1\assignment1.c pp(113) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<cha
r> >' (or there is no acceptable conversion)
C:\Documents and Settings\genesis\Desktop\assignment1\assignment1.c pp(115) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<cha
r> >' (or there is no acceptable conversion)
Error executing cl.exe.
assignment1.obj - 2 error(s), 0 warning(s)
i received the error above .. i compiled using Ms Visual C++ ... i have no idea it means what ...
Make sure you have all these.
Code:#include <iostream> using std::cout; using std::endl; #include <fstream> using std::ifstream; #include <string> using std::string;
source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense
>is "while(fin_f1.good())" an infinite loop the way you put it (I've never used .good() and .is_open())
No. When you reach EOF, the flag that good() looks at is unset and the loop ends.
My best code is written with the delete key.
^ you learn something new every day... I forgot about EOF
what alphaoide said sounds like it could be the problem... that's what I was guessing it was anyway...
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
but i did use
i thoughtCode:using namespace std;
should be included in the "using namespace std;"Code:#include <iostream> using std::cout; using std::endl; #include <fstream> using std::ifstream; #include <string> using std::string;
it is, but that method is considered a little bit better than "using namespace std"
how come ? shouldnt "using namespace std" better ? it saves more lines
yes but everything isnt about lines "using namespace std" will include absolutely everything there is in the namespace and I doubt you will use everything, therefore people more often use "using std::something" or "std::something".
yeah, from what I've seen/heard, people mostly like these ways:I use the first way If I'm going to be using something alot, like cout,endl,cin,etc. for stuff like ios, I usually use the second method... even though it looks wierd with ios:Code:using std::cout; //or std::cout<<"hello\n"; std::cin>>variables;Code:using std::ifstream; ifstream infile(filename,std::ios::trunc);
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT