|
|
#1 |
|
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;
}
|
|
|
|
0
|
|
|
#2 |
|
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. |
|
|
|
0
|
|
|
#3 |
|
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;
}
|
|
|
|
0
|
|
|
#4 |
|
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 |
|
|
|
0
|
|
|
#5 |
|
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;
}
|
|
|
|
0
|
|
|
#6 |
|
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. |
|
|
|
0
|
|
|
#7 |
|
There's actually quite a bit of vision behind C++. Check out "The Design and Evolution of C++" some time.
__________________
Computer Programming: An Introduction for the Scientifically Inclined So how much does an iPhone developer make? My iPhone games: Sjoelen, Mazer (free) |
|
|
|
0
|
|
|
#8 |
|
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:
Destroy them if you want Debug/gcc-4.2 to execute correctly. |
|
|
|
0
|
|
|
#9 | |
|
Quote:
|
||
|
|
0
|
|
|
#10 | |
|
Quote:
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 Code:
GCC_PREPROCESSOR_DEFINITIONS = (
"_GLIBCXX_DEBUG=1",
"_GLIBCXX_DEBUG_PEDANTIC=1",
);
|
||
|
|
0
|
|
|
#11 |
|
how do i destroy those things?
because i have the same problem |
|
|
|
0
|
|
|
#12 |
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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.








Linear Mode

