Thread: CPP: cannot read with ifstream?

  1. #1
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126

    Question CPP: cannot read with ifstream?

    Hi,

    I am having trouble reading some files in standard cpp.
    (The path is correct, but when reading the files I don't get any input)
    And I think posix permissions might be causing the problem
    So when I do a:
    ls -all
    I get
    Code:
    -rwxrwxrwx@  1 nacho4d  staff    276 Feb 24 21:32 llahparam.txt
    -rwxrwxrwx@  1 nacho4d  staff   3648 Feb 24 21:32 paperlist.txt
    -rwxrwxrwx@  1 nacho4d  staff    230 Feb 24 22:14 pts1.txt
    -rwxrwxrwx@  1 nacho4d  staff    267 Feb 24 21:33 pts2.txt
    Which means my permissions are ok,(since I did chmod 777) but what is the @ mark at the end?
    I've realized that not all files have this mark, and might be a coincidence but the ones I cannot read have this mark.

    I read the file, but It is like it were empty. so I get not error, nothing.
    When I see it in the finder I can see the content
    but when doing
    Code:
    cat file.txt
    in the terminal nothing appears. (So is seems to be empty?)

    Code:
    ifstream in(name); //name is a absolute path, something like "/Users/nacho4d/myfile.txt"
    if(!in.fail()){
    	in >> w;
    	in >> h;
    	in >> fx;
    	in >> fy;
    	in >> cx;
    	in >> cy;
    	in >> k1;
    	in >> k2;
    	in >> p1;
    	in >> p2;
    }	
    in.close();

    The file I am trying to read was created in Windows but I have already checked that is UTF8 encoded and it has UNIX line endings.
    I also tried creating a new file and copying the content and it didn't work.
    WHY?????


    Thanks.
    Mac OS 10.6 Snow Leopard : Darwin

  2. #2
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126
    Thanks ...
    I realized it was a known bug of Xcode 3.2.1
    I have to Delete _GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1 flags from Degug Configuration.

    Solution is here:
    Xcode 3.2.1 and C++ string fails! - Stack Overflow
    Mac OS 10.6 Snow Leopard : Darwin

  3. #3
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Not sure if this is a closed problem since I didn't see a solution but....is it possible that on your system the @ means that the file is actually a symlink?

    Also I see one set of files when you ls -all and a different one when you cat file.txt...is file.txt even there?

    As for Windows/*NIX file differences, dos2unix and unix2dos are your friends...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf function won't read my float value...?
    By qpsnhalfs in forum C Programming
    Replies: 8
    Last Post: 07-07-2009, 11:01 PM
  2. [question] ifstream read file, thanks!
    By userpingz in forum C++ Programming
    Replies: 6
    Last Post: 05-19-2009, 06:38 PM
  3. bytes lost with partial read in UDP
    By mynickmynick in forum Networking/Device Communication
    Replies: 3
    Last Post: 03-31-2009, 02:06 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  5. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 04:23 PM