Linux Pico Editor

Compiling a C++ program in the Linux Pico Editor

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 5536 Views - Last Post: 14 September 2008 - 02:03 PM Rate Topic: -----

#1 chaoticabyss99   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 94
  • Joined: 14-June 08

Linux Pico Editor

Post icon  Posted 13 September 2008 - 10:22 PM

I'm trying to get a short program done in the Linux Pico Editor. I've already got the code written, I'm just a little confused about how to do it in the Linux command line environment and compile it and then have it show the results.

Does anyone know how to accomplish this task?
Is This A Good Question/Topic? 0
  • +

Replies To: Linux Pico Editor

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,157
  • Joined: 10-May 07

Re: Linux Pico Editor

Posted 13 September 2008 - 10:29 PM

Assuming that you are using gcc : gcc dash o *output name* -i file.c
You should also be able to get away with make file where file represents the file.c filename like in the previous example.
Was This Post Helpful? 0
  • +
  • -

#3 chaoticabyss99   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 94
  • Joined: 14-June 08

Re: Linux Pico Editor

Posted 13 September 2008 - 10:58 PM

View Postno2pencil, on 13 Sep, 2008 - 10:29 PM, said:

Assuming that you are using gcc : gcc dash o *output name* -i file.c
You should also be able to get away with make file where file represents the file.c filename like in the previous example.


Thanks. That did help!
Was This Post Helpful? 0
  • +
  • -

#4 chaoticabyss99   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 94
  • Joined: 14-June 08

Re: Linux Pico Editor

Posted 14 September 2008 - 11:12 AM

OK, now I'm having a problem with some error messages. They are as follows:

test.cpp:3: error: 'cout' has not been declared
test.cpp:4: error: 'cin' has not been declared
test.cpp:5: error: 'endl' has not been declared
test.cpp: In function 'int main()':
test.cpp:14: error: 'cout' was not declared in this scope
test.cpp:14: error: 'endl' was not declared in this scope
test.cpp:15: error: 'cin' was not declared in this scope


Here is what I have
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main()
{
//declare variables
float ftemp;
float ctemp;

cout << "Please enter the temperature in degrees celcius: " << endl;
cin >> ctemp;

//convert temperature from celcius to fahrenheit
ftemp = 9/5 * ctemp + 32;

//display result of conversion
cout << "The equivalent temperature in degrees fahrenheit is: " << ftemp << " "
<< "degrees fahrenheit." << endl;

return 0;

}


Anyone know what the problem is?

This post has been edited by chaoticabyss99: 14 September 2008 - 12:31 PM

Was This Post Helpful? 0
  • +
  • -

#5 chaoticabyss99   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 94
  • Joined: 14-June 08

Re: Linux Pico Editor

Posted 14 September 2008 - 01:10 PM

Here is the exact code I'm using in the Pico Editor:

#include <iostream>
#include <conio.h>
using std::cout;
using std::cin;
using std::endl;

int main()
{

//declare variables
float ftemp; //fahrenheit temp
float ctemp; //celcius temp

cout << "Please enter the temperature in degrees celcius: " << endl;
cin >> ctemp; //read in celcius temp

//convert temperature from celcius to fahrenheit
ftemp = 9/5 * ctemp + 32;

//display result of conversion
cout << "The equivalent temperature in fahrenheit is: " << ftemp << ""
	 << "degrees fahrenheit." << endl;


_getch();

}



Now I'm getting these error messages:

test.cpp:2:19: error: conio.h: No such file or directory
test.cpp: In function 'int main()' :
test.cpp:25: error: '_getch' was not declared in this scope


I don't understand why this compiles and executes with no problems in MS Visual C++, but I'm getting errors when I'm trying to use the Linux command line environment.

Any ideas?
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,157
  • Joined: 10-May 07

Re: Linux Pico Editor

Posted 14 September 2008 - 01:12 PM

View Postchaoticabyss99, on 14 Sep, 2008 - 04:10 PM, said:

#include <conio.h>


...
Any ideas?

conio.h :D
Was This Post Helpful? 0
  • +
  • -

#7 Locke   User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 550
  • View blog
  • Posts: 5,624
  • Joined: 20-March 08

Re: Linux Pico Editor

Posted 14 September 2008 - 01:12 PM

Replace your 3 using lines with this single one...

using namespace std;


That should fix a few problems.
____________________________________

And your conio.h problem is it's only included in some compilers (I think...not familiar with a lot of C++), so it may not be in yours, giving you errors on that header file.

EDIT: From no2Pencil's post...conio.h is Windows only. :)

Also, I noticed you're missing your return statement...

This post has been edited by Locke37: 14 September 2008 - 01:17 PM

Was This Post Helpful? 0
  • +
  • -

#8 chaoticabyss99   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 94
  • Joined: 14-June 08

Re: Linux Pico Editor

Posted 14 September 2008 - 01:17 PM

View PostLocke37, on 14 Sep, 2008 - 01:12 PM, said:

Replace your 3 using lines with this single one...

using namespace std;


That should fix a few problems.
____________________________________

And your conio.h problem is it's only included in some compilers (I think...not familiar with a lot of C++), so it may not be in yours, giving you errors on that header file.



I took out the <conio.h> piece and replaced the 3 using statements with using namespace std;

Now, I end up with a bunch of 'undefined reference' messages :crazy:
Was This Post Helpful? 0
  • +
  • -

#9 Locke   User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 550
  • View blog
  • Posts: 5,624
  • Joined: 20-March 08

Re: Linux Pico Editor

Posted 14 September 2008 - 01:20 PM

...umm? :unsure:

Just post your new code. That'll help us figure it out.

This is just ANSI C++...this can't just be messing up because of Linux...

This post has been edited by Locke37: 14 September 2008 - 01:22 PM

Was This Post Helpful? 0
  • +
  • -

#10 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6727
  • View blog
  • Posts: 31,157
  • Joined: 10-May 07

Re: Linux Pico Editor

Posted 14 September 2008 - 01:23 PM

View Postchaoticabyss99, on 14 Sep, 2008 - 04:17 PM, said:

I took out the <conio.h> piece and replaced the 3 using statements with using namespace std;

Now, I end up with a bunch of 'undefined reference' messages :crazy:

If you use functions defined in conio.h (or any header file) & then you remove it, what else would you expect to happen?

Since conio.h is not available for Linux, it goes without saying that you won't be able to use the functions defined in it. Welcome to porting code 101. Your best bet is to use the ncruses library for Linux, find other source code, or get a better understanding for the code you are using. Even though it's console code, it isn't as simply as cut-paste-compile.
Was This Post Helpful? 0
  • +
  • -

#11 Locke   User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 550
  • View blog
  • Posts: 5,624
  • Joined: 20-March 08

Re: Linux Pico Editor

Posted 14 September 2008 - 01:26 PM

What functions are they using from conio.h besides getch()?
Was This Post Helpful? 0
  • +
  • -

#12 chaoticabyss99   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 94
  • Joined: 14-June 08

Re: Linux Pico Editor

Posted 14 September 2008 - 01:27 PM

View PostLocke37, on 14 Sep, 2008 - 01:20 PM, said:

...umm? :unsure:

Just post your new code. That'll help us figure it out.

This is just ANSI C++...this can't just be messing up because of Linux...



#include <iostream>
using namespace std;

int main()
{

//declare variables
float ftemp; //fahrenheit temp
float ctemp; //celcius temp

cout << "Please enter the temperature in degrees celcius: " << endl;
cin >> ctemp; //read in celcius temp

//convert temperature from celcius to fahrenheit
ftemp = 9/5 * ctemp + 32;

//display result of conversion
cout << "The equivalent temperature in fahrenheit is: " << ftemp << ""
	 << "degrees fahrenheit." << endl;

return 0;

}

Was This Post Helpful? 0
  • +
  • -

#13 Locke   User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 550
  • View blog
  • Posts: 5,624
  • Joined: 20-March 08

Re: Linux Pico Editor

Posted 14 September 2008 - 01:30 PM

I see nothing wrong...:unsure:

Then again, I'm new to C++...

This post has been edited by Locke37: 14 September 2008 - 01:34 PM

Was This Post Helpful? 0
  • +
  • -

#14 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6248
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Linux Pico Editor

Posted 14 September 2008 - 01:40 PM

It should compile fine, but you need to change your conversion formula a little:
ftemp = ((9 / 5.0) * ctemp) + 32;

Was This Post Helpful? 0
  • +
  • -

#15 Locke   User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 550
  • View blog
  • Posts: 5,624
  • Joined: 20-March 08

Re: Linux Pico Editor

Posted 14 September 2008 - 01:44 PM

View PostJackOfAllTrades, on 14 Sep, 2008 - 01:40 PM, said:

It should compile fine, but you need to change your conversion formula a little:
ftemp = ((9 / 5.0) * ctemp) + 32;


Actually I'm fairly sure they don't have to do the conversion that way, as C++ reads from left to right when the operators are equal in precedence. The + would still be last...the / would be first.

Although, I would agree to change it, it's just more understandable.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2