LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-10-2016, 02:46 PM   #1
FortuneTeller5000
LQ Newbie
 
Registered: Mar 2016
Posts: 6

Rep: Reputation: Disabled
What the hell happened to <iostream> (plain C)?


Hey, so I'm a beginner programmer, and I tried running some code with this off another programming website so I could better understand how to use character arrays:

#include <stdio.h>
#include <stdlib.h>

int main ()
{
char ask[]= "Enter your first name: ";
char answer[]= "So your name is ";
char name[100];

cout << ask;
ask >> name;
cout << answer << name << ".";
}

I found out that in order for this to work, you need the iostream header, which is either just <iostream> or <iostream.h>, which didn't work because this file is not on my computer. I even downloaded the newest gcc gnu compiler by itself to see if it would be in there, but it isn't!

Is this considered an obsolete way to program? What the hell is going on?

Thanks in advance
 
Old 03-10-2016, 03:33 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
iostream, cout, cin, etc. are C++, not C.
 
Old 03-10-2016, 03:47 PM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,220

Rep: Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319
cout and iostream are C++, not c.

EDIT: ninja'd.
 
Old 03-10-2016, 06:18 PM   #4
FortuneTeller5000
LQ Newbie
 
Registered: Mar 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dugan View Post
cout and iostream are C++, not c.

EDIT: ninja'd.
lol, makes sense
 
Old 03-10-2016, 08:50 PM   #5
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by FortuneTeller5000 View Post
I found out that in order for this to work, you need the iostream header, which is either just <iostream> or <iostream.h>, which didn't work because this file is not on my computer. I even downloaded the newest gcc gnu compiler by itself to see if it would be in there, but it isn't!
I'm surprised about that. Modern gcc compilers usually have the ability to compile C or C++ code and include the <stdio.h> or <iostream> files as a matter of course.
 
Old 03-10-2016, 10:56 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> Modern gcc compilers usually have the ability to compile C or C++ code

True.

> and include the <stdio.h> or <iostream> files

cpp does that, when encounters an #include <stdio.h> or #include <iostream> -- not automagically

Last edited by NevemTeve; 03-11-2016 at 12:17 AM.
 
Old 03-11-2016, 04:56 AM   #7
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by NevemTeve View Post
> and include the <stdio.h> or <iostream> files

cpp does that, when encounters an #include <stdio.h> or #include <iostream> -- not automagically
Sorry, poor phrasing. I didn't mean to imply "automagically".
 
Old 03-11-2016, 05:24 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Then I don't get your point. Methinks nor even the best cpp could include a header that isn't installed on the computer.
 
Old 03-11-2016, 07:58 AM   #9
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Wait, what?

Are you saying that the files are not installed on the computer but they will be included in a program anyway if the source code contains the statements #include <stdio.h> or #include <iostream>?

Last edited by psionl0; 03-11-2016 at 08:00 AM.
 
Old 03-11-2016, 08:15 AM   #10
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,621
Blog Entries: 40

Rep: Reputation: Disabled
Nobody has made such a statement.

If you include <iostream> it is you who must ensure its availability, the same with <stdio.h>. If you include iostream in your C-code (normally an error), *AND* the header is available, the C-compiler acts schizophrenic and compiles it anyway.

I cannot say that I appreciate this laxity. In my opinion, C should stay C and C++ should stay C++. The compiler should explode or make the display rotate or fart or whatever, when the code is mixing headers or other elements of both languages. But someone has certainly had a reason to make it act differently.
 
Old 03-11-2016, 08:32 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Guess we are over-complicating this. OP couldn't compile his C-program, for different reasons: 1) it wasn't a C-program. 2) he couldn't include 'iostream' header, because he had never installed it on his computer.
 
Old 03-11-2016, 08:46 AM   #12
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
It's hardly a complicated matter. OP downloaded and installed the newest gcc compiler but says that the file <iostream> wasn't there. That's what surprised me.
 
Old 03-11-2016, 09:05 AM   #13
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
(In a stricter terminology 'gcc' doesn't cover 'g++' and 'libstdc++')
 
Old 03-11-2016, 11:38 AM   #14
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,220

Rep: Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319Reputation: 5319
Try this:

Code:
#include <iostream>

using namespace std;

int main ()
{
    string ask = "Enter your first name: ";
    string answer = "So your name is ";
    string name;

    cout << ask;
    ask >> name;
    cout << answer << name << ".\n";
    return 0;
}
Save it as "test.cpp" and build it with:

Code:
g++ test.cpp
That will produce a file called "a.out". Run it with:

Code:
./a.out
Did that work?
 
1 members found this post helpful.
Old 03-11-2016, 01:55 PM   #15
FortuneTeller5000
LQ Newbie
 
Registered: Mar 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
thanks dugan, ill try that out when i get around to it. I think ill just start a new project in C++
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] iostream.h exists, yet facing "iostream.h: No such file or directory" mq15 Linux - Software 13 01-02-2010 09:13 AM
Linux iostream vs Windows iostream davidguygc Programming 2 05-13-2007 09:13 PM
What the hell happened to my Gnome?? valdiorn Linux - Software 6 08-08-2005 06:05 PM
What the hell just happened? crnchyfrog Mandriva 1 05-30-2005 03:31 AM
What the hell happened?!?!?!? TheRealDeal Linux - General 2 09-20-2003 07:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration