Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to use iostream.h on C on Xcode?

First of all I must say I'm a NOOB both in programming C as in Xcode.


I started college this month and all the basic programming lessons are in C and using iostream.h file. And averybody uses PC/Windows there.


I already had Xcode installed and after searching for a while I've downloaded and installed Command Line Tools. After the installation I've found IOStream.h file on /System/Library/Frameworks/Kernel.framework/Versions/A/Headers/IOKit/stream


I've tried to include the file on my C file but it didnt work. It says some files are missing: /System/Library/Frameworks/Kernel.framework/Versions/A/Headers/IOKit/stream/IOS tream.h:9:10: 'IOKit/IOService.h' file not found


If i try to correct the file path it says I dont have permission. And if i change the permission it complains about other files included in other files.


When I create a project it already opens a main.c file including a stdio.h file (that i dont know where in my computer it is) but when i run the build has no errors:

#include <stdio.h>


When i try to include iostream it sugests me IOKit, which has no iostream file. The closest i found was a

IOKit/stream/IOStreamLib.h. Seems those files sugested by Xcode are in another directory: /System/Library/Frameworks/IOKit.framework/Versions/A/Headers/stream


If i try to include only "iostream.h" or "iostream" it doesn't work neither.


What should I do to use commands as cin and cout on my C code?

Posted on May 31, 2013 10:26 PM

Reply
3 replies

Jun 1, 2013 6:02 AM in response to Diogo Werner

iostream is a C++ I/O library; it isn't used in C programming. What language is this course using, because it is possible to use the C++ language and effectively write standard C programs in it. It's a bad idea, because it's confusing and teaches all sorts of bad lessons (an example of which you might be in the middle of experiencing). But it is possible.


If you are actually doing C++ programming, then you need to create a C++ project in Xcode, and then:


#include <iostream>


At that point, you can use cin and cout by referring to their full names, eg:


std::cout << "write this sentence to cout" << std::endl;


or, you can drop the "std::" part of the name by including a using directive:


using namespace std

How to use iostream.h on C on Xcode?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.