Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 2, 2009, 04:50 PM   #1
timmsu
macrumors newbie
 
Join Date: Oct 2009
C++, XCode 3.2 & fstream.h - don't working((

I have Snow Leopard and Xcode 3.2. And I need to write little module for my program, which should read file with integer in first line (number of coordinates) and a lot float numbers in other lines (triangulation coordinates).

So, I wrote this program:
Code:
#include <iostream>
#include <fstream>

using namespace std;

int main () {
	
	ifstream ffile("pcp.txt", ifstream::in);

	int nu;
	
	cout << ffile.is_open() << endl; //Verifying was file opened or not`
	
	ffile>>nu; //Trying to read first number from file
	cout << nu;

	ffile.close();
    return 0;
}
It's just first lines, but it don't work well. File pcp.txt located in binary's directory (/build/debug/) and program says that opens it. But file content some numbers like 123 45.67 32.67 etc. And XCode says that nu == 0. I don't know why! This program works perfectly in my friend's Visual Studio 2008. Please, help me!
timmsu is offline   0 Reply With Quote
Old Oct 2, 2009, 05:05 PM   #2
darkwing
macrumors 65816
 
Join Date: Jan 2004
Send a message via AIM to darkwing
After you create ffile, add a line:

if(!ffile) cout << "bad!" << endl;

That'll tell you if the file is really being open or not.
__________________
A gay man has the same right to marry a woman as I do.
darkwing is offline   0 Reply With Quote
Old Oct 2, 2009, 06:00 PM   #3
electroshock
macrumors 6502a
 
electroshock's Avatar
 
Join Date: Sep 2009
Could do it like this:

Code:
#include <iostream>
#include <fstream>

using namespace std;

int main () {
        ifstream inputData;
        float    number;

        inputData.open("pcp.txt");
        if (!inputData) {
                cerr << "Err... ummm... sorry, dude, but couldn't open the blasted #@$()@#$! file" << endl;
                // EPIC FAIL
                exit(1);
        }

        inputData >> number;

        while (!inputData.eof() ) {
                cout << "The number is: " << number << endl;
                inputData >> number;
        }

        inputData.close();
        return 0;
}
electroshock is offline   0 Reply With Quote
Old Oct 2, 2009, 06:05 PM   #4
wakwe
macrumors newbie
 
Join Date: Oct 2009
I had almost forgotten how much i dislike c++. that's what happens when you pile crap onto a programming language without a vision.

die c++ die.

i <3 c, python, even obj-c
wakwe is offline   0 Reply With Quote
Old Oct 2, 2009, 09:12 PM   #5
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
If you're using Xcode 3.2 be aware that in builds running/debugging under the Debug setting istream may, or may not, fail. My solution is to set the debug target to GCC 4.0 when debugging input streams.

Code:
#include <iostream>
#include <fstream>

int main()
{
    std::string     str;
    int             n = 6;
    std::ifstream   is("pcp.txt");
    if ( is.is_open())
    {
        is >> str;
        std::cout << str << std::endl;
        
        is >> n;
        std::cout << n << std::endl;
    }

    is.close();

    return 0;
}
lloyddean is offline   0 Reply With Quote
Old Oct 3, 2009, 02:02 AM   #6
timmsu
Thread Starter
macrumors newbie
 
Join Date: Oct 2009
1. I already have verification if file opened or not - it opens ok.

2. When I add while, it just returns zeros, like:

The number is: 0
The number is: 0
The number is: 0
The number is: 0
The number is: 0
The number is: 0
The number is: 0
The number is: 0
The number is: 0
etc...

3. Just tryed to use gcc in Terminal - everything works great, but not in XCode((

Last edited by timmsu; Oct 3, 2009 at 03:42 AM.
timmsu is offline   0 Reply With Quote
Old Oct 3, 2009, 04:36 AM   #7
Sander
macrumors 6502
 
Join Date: Apr 2008
Quote:
Originally Posted by wakwe View Post
I had almost forgotten how much i dislike c++. that's what happens when you pile crap onto a programming language without a vision.

die c++ die.

i <3 c, python, even obj-c
There's actually quite a bit of vision behind C++. Check out "The Design and Evolution of C++" some time.
Sander is offline   0 Reply With Quote
Old Oct 4, 2009, 12:17 PM   #8
KonaBlend
macrumors newbie
 
Join Date: Oct 2008
Under Xcode 3.2 when creating a new project based on stdc++ project template the target build settings for Debug configuration adds preprocessor macros which are incompatible with gcc-4.2:
  • _GLIBCXX_DEBUG=1
  • _GLIBXX_DEBUG_PEDANTIC=1

Destroy them if you want Debug/gcc-4.2 to execute correctly.
KonaBlend is offline   0 Reply With Quote
Old Oct 31, 2009, 10:33 AM   #9
mark517
macrumors newbie
 
Join Date: Oct 2009
Quote:
Originally Posted by KonaBlend View Post
Under Xcode 3.2 when creating a new project based on stdc++ project template the target build settings for Debug configuration adds preprocessor macros which are incompatible with gcc-4.2:
  • _GLIBCXX_DEBUG=1
  • _GLIBXX_DEBUG_PEDANTIC=1

Destroy them if you want Debug/gcc-4.2 to execute correctly.
Is there a way to make the destruction of these preprocessor macros the default for any new c++ project that is created?
mark517 is offline   0 Reply With Quote
Old Nov 9, 2009, 12:24 AM   #10
KonaBlend
macrumors newbie
 
Join Date: Oct 2008
Quote:
Originally Posted by mark517 View Post
Is there a way to make the destruction of these preprocessor macros the default for any new c++ project that is created?
Looks like this is still an issue as of Xcode 3.2.1...

You could try editing the following template project files manually:
Code:
/Developer/Library/Xcode/Project Templates/Application/Command Line Tool/C++ Tool/C++Tool.xcodeproj/project.pbxproj
/Developer/Library/Xcode/Project Templates/Framework & Library/STL C++ Library/C++ Dynamic Library/CppShared.xcodeproj/project.pbxproj
/Developer/Library/Xcode/Project Templates/Framework & Library/STL C++ Library/C++ Standard Dynamic Library/CppShared.xcodeproj/project.pbxproj
/Developer/Library/Xcode/Project Templates/System Plug-in/Generic C++ Plug-in/Generic C++ Plugin.xcodeproj/project.pbxproj
And stripping out these (or similar) 4 lines:
Code:
GCC_PREPROCESSOR_DEFINITIONS = (
    "_GLIBCXX_DEBUG=1",
    "_GLIBCXX_DEBUG_PEDANTIC=1",
);
KonaBlend is offline   0 Reply With Quote
Old Mar 13, 2010, 02:45 AM   #11
CuteBoA
macrumors newbie
 
Join Date: Mar 2010
how do i destroy those things?
because i have the same problem
CuteBoA is offline   0 Reply With Quote
Old Mar 13, 2010, 12:34 PM   #12
chown33
macrumors 601
 
Join Date: Aug 2009
Quote:
Originally Posted by CuteBoA View Post
how do i destroy those things?
because i have the same problem
http://forums.macrumors.com/showthread.php?t=867839
chown33 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Can I unlock a 3GS with 05.16.02 Baseband and iOS 4.3.2? Alvi Jailbreaks and iOS Hacks 3 May 16, 2011 12:42 PM
iPhone 4 "not eligible" for 4.3.2 update? CoffeeMonkey iPhone Tips, Help and Troubleshooting 3 Apr 19, 2011 07:40 AM
Anyone else still on 3.2.1 koobcamuk iPad 5 Nov 29, 2010 05:24 PM
xcode 3.2.1 c++ fstream problem "NOT SAME PROBLEM IN EVERY OTHER POST!!!" modernlifeislov Mac Programming 7 Apr 29, 2010 11:52 PM
Mail 3.2 & Gmail IMAP - Where are my folders?? jaydie515 Mac Applications and Mac App Store 0 Feb 27, 2008 11:08 AM


All times are GMT -5. The time now is 03:19 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC