file system

This is a discussion on file system within the C++ Programming forums, part of the General Programming Boards category; 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 ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    55

    file system

    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 ?

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    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

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Well,
    Code:
    void main()
    is one thing. main always returns an int.

    As to what else is wrong... It would be helpful to know what problems you are having with it.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    55
    --------------------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 ...

  5. #5
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    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

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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.

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    ^ 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

  8. #8
    Registered User
    Join Date
    Oct 2003
    Posts
    55
    but i did use

    Code:
    using namespace std;
    i thought
    Code:
    #include <iostream>
    using std::cout;
    using std::endl;
    
    #include <fstream>
    using std::ifstream;
    
    #include <string>
    using std::string;
    should be included in the "using namespace std;"

  9. #9
    Registered User
    Join Date
    Aug 2003
    Posts
    1,205
    it is, but that method is considered a little bit better than "using namespace std"

  10. #10
    Registered User
    Join Date
    Oct 2003
    Posts
    55
    how come ? shouldnt "using namespace std" better ? it saves more lines

  11. #11
    Registered User
    Join Date
    Aug 2003
    Posts
    1,205
    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".

  12. #12
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    yeah, from what I've seen/heard, people mostly like these ways:
    Code:
    using std::cout;
    //or
    std::cout<<"hello\n";
    std::cin>>variables;
    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::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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. Replies: 4
    Last Post: 10-21-2003, 04:28 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21