LinuxQuestions.org
Visit Jeremy's Blog.
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-26-2018, 01:37 PM   #1
kjoygray75
LQ Newbie
 
Registered: Mar 2018
Posts: 3

Rep: Reputation: Disabled
I cant get a C++ program to print to the terminal (Lubunutu and G++)


This is a fresh install of Lubuntu and the first program I've written since setting it up. For some reason the program prints no output to the terminal.

I tried making a test program to make sure it wasn't just an error on my part:
Code:
#include <iostream>

int main(int argc, char** argv) {
	std::cout<<"butts"<<std::endl;
	std::cout<<"butts";
	std::cout.flush();
	return 0;
}
The result is the same though. I've never had this issue before so what could be the hangup?
 
Old 03-26-2018, 01:43 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 6,778
Blog Entries: 12

Rep: Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411
That program works.

How are you compiling it and running it?
 
Old 03-26-2018, 01:47 PM   #3
kjoygray75
LQ Newbie
 
Registered: Mar 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
That program works.

How are you compiling it and running it?
Code:
g++ test.cpp -o test
I'm downloading another compiler at the moment to see if it's maybe a problem with my development environment. I'm really stumped on what could cause this though.

Last edited by kjoygray75; 03-26-2018 at 01:49 PM. Reason: add info
 
Old 03-26-2018, 02:01 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,503

Rep: Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080
It's one of the oldest problems in Unix:
Code:
g++ -o test test.cpp
./test # execute your program
test   # execute /bin/test

Last edited by NevemTeve; 03-26-2018 at 02:02 PM.
 
Old 03-26-2018, 02:06 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 6,778
Blog Entries: 12

Rep: Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411
Yeah ... don't use the name test.
 
Old 03-26-2018, 02:07 PM   #6
kjoygray75
LQ Newbie
 
Registered: Mar 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
It's one of the oldest problems in Unix:
Code:
g++ -o test test.cpp
./test # execute your program
test   # execute /bin/test
lmao,that did it
Thank you for the help!
 
Old 03-26-2018, 02:09 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Slackware 14.2 / Slackware 14.2 current / Manjaro
Posts: 6,397

Rep: Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238
it worked both ways for me using same compiler
Code:
$ g++ test.cpp -o test 

$ g++ -o test test.cpp

$ ./test
butts

Last edited by BW-userx; 03-26-2018 at 02:11 PM.
 
Old 03-26-2018, 02:30 PM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 6,778
Blog Entries: 12

Rep: Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411Reputation: 2411
Quote:
Originally Posted by BW-userx View Post
it worked both ways for me using same compiler
Code:
$ ./test
Look more detailed at NevemTeve's description of the problem.

Such as where it says:
Quote:
./test # execute your program
test # execute /bin/test
On my system it actually is /usr/bin/test, but doesn't matter, their point about how to invoke is the main point there.
 
Old 03-26-2018, 02:48 PM   #9
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: MID-SOUTH USA
Distribution: Slackware 14.2 / Slackware 14.2 current / Manjaro
Posts: 6,397

Rep: Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238
Quote:
Originally Posted by rtmistler View Post
Look more detailed at NevemTeve's description of the problem.

Such as where it says:On my system it actually is /usr/bin/test, but doesn't matter, their point about how to invoke is the main point there.
apart from getting the right program named test running due to path assignment, I thought the issue was the compiling of a program.

using a same name is not an issue even though it can cause issues if not executed properly. that is the issue not the program name itself. I do that all of the time, or sometimes when I am working on my program that I have installed, and test using the same name in a local directory. anyways, I do hope the OP has learned something here.

thanks or the clarification.

Last edited by BW-userx; 03-26-2018 at 02:50 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Using libreoffice or anything to print anything from terminal MattFly Programming 5 09-06-2015 04:06 PM
Terminal print command dunnery Linux - Newbie 5 04-24-2015 08:24 PM
How do i print a terminal screen? glenn69 Linux - Newbie 2 02-26-2012 04:04 PM
Running program from terminal with & does nothing, program stops DittoAlex Linux - General 1 10-05-2007 01:35 AM
print the terminal saosurya Red Hat 1 09-11-2005 10:54 PM

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

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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration