Jump to content

Eclipse C++ Function printf could not be resolved

FaiL___

Hi, I am planning on moving from Windows to Linux so have just decided to try eclipse as a visual studio alternative, but I just have a simple program at the minute, and printf isn't working (code below). I have seen posts online but not found a definite fix.

Thanks in advance.

 

#include <stdio.h>

int main()
{
	printf("hi");
	return 0;
}

 

There are 10 types of people in the world. Those that understand binary and those that don't.

Link to comment
Share on other sites

Link to post
Share on other sites

printf ("%s \n", "hi");

try this

i7-4790k | MSI Z97 GAMING-5 | Corsair Vengeance 16 GB | Samsung EVO-850 250GB SSD & WD blue 1 TB HDD | EVGA 1070 SC | Red NZXT H440 | Cooler Master G650W

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, Railgun said:

printf ("%s \n", "hi");

try this

unfortunately that did not work, for a little while, it said that "hi" was not spelled right, and it was showing the correct details for printf when I hovered over it, but I changed the " to ' on hi and it fixed that problem, but went back to saying function could not be resolved

There are 10 types of people in the world. Those that understand binary and those that don't.

Link to comment
Share on other sites

Link to post
Share on other sites

Hmm. I am by NO means an expert on C++, but according to everything on this; your code is right. This leads me to believe there is a compatibility issue, or otherwise something inhibiting the success of your code that is located elsewhere. Try stepping into it to see if you can find out what's going on

i7-4790k | MSI Z97 GAMING-5 | Corsair Vengeance 16 GB | Samsung EVO-850 250GB SSD & WD blue 1 TB HDD | EVGA 1070 SC | Red NZXT H440 | Cooler Master G650W

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Railgun said:

Hmm. I am by NO means an expert on C++, but according to everything on this; your code is right. This leads me to believe that there is a compatibility issue, or otherwise something inhibiting the success of your code that is located elsewhere. Try stepping into it to see if you can find out what's going on

It's not in the running of the code, it won't even let me run the code because of the error (well, I assume because of the error, it actually says "Launch failed: Binary not found", but this error is just being detected by the IDE itself.

There are 10 types of people in the world. Those that understand binary and those that don't.

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, FaiL___ said:

It's not in the running of the code, it won't even let me run the code because of the error (well, I assume because of the error, it actually says "Launch failed: Binary not found", but this error is just being detected by the IDE itself.

Still kinda sounds like a separate issue. Before you go on to further troubleshooting, try removing the \n as it might be causing your message to not appear

i7-4790k | MSI Z97 GAMING-5 | Corsair Vengeance 16 GB | Samsung EVO-850 250GB SSD & WD blue 1 TB HDD | EVGA 1070 SC | Red NZXT H440 | Cooler Master G650W

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Railgun said:

Still kinda sounds like a separate issue. Before you go on to further troubleshooting, try removing the \n as it might be causing your message to not appear

image.png.ec5b13395fe83be3afcc7ebb7cde4d7d.png

This is what it is saying in the IDE (I just removed the \n). It's not the running of that code that is the issue, it's just the actual syntax by the sounds of it.

 

PS I also changed the hi text to a variable to see if that would help. It didn't.

There are 10 types of people in the world. Those that understand binary and those that don't.

Link to comment
Share on other sites

Link to post
Share on other sites

Isn’t char for single letters? 

 

For C++ I think you’d want to use stdio with cin and cout for console input and output. 

 

(RIP mobile doesn’t have code thingy)

 

#include <std.io>

 

int main (){

short foo;

Cout << “hello world” << endl;

cin >> foo;

return 0;

}

 

i Never used C syntax knowingly with C++. 

Link to comment
Share on other sites

Link to post
Share on other sites

On 28/04/2018 at 2:27 AM, FaiL___ said:

It's not in the running of the code, it won't even let me run the code because of the error (well, I assume because of the error, it actually says "Launch failed: Binary not found", but this error is just being detected by the IDE itself.

That has nothing to do with your code, it cannot find the executable. The code should work. Does it compile? Where is the resulting executable stored? It sounds more like you haven't got the IDE configured correctly than something wrong with the code.

As for printf not resolved: https://stackoverflow.com/questions/19305406/eclipse-c-c-function-printf-could-not-be-resolved

Try right click on project > Index > Rebuild.

 

Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9370 | CPU: i5 10510U | RAM: 16 GB

Server: CPU: i5 4690k | RAM: 16 GB | Case: Corsair Graphite 760T White | Storage: 19 TB

Link to comment
Share on other sites

Link to post
Share on other sites

On 28-4-2018 at 2:41 AM, FaiL___ said:

PS I also changed the hi text to a variable to see if that would help. It didn't.

Made a little mistake there; should be:

const char* hi = "Hi"; //Double quotes for a string literal...

The original should've compiled fine tough, there's something wrong with your IDE setup. Looks like it can't find the required header (stdio.h)

Link to comment
Share on other sites

Link to post
Share on other sites

On 4/28/2018 at 5:16 AM, FaiL___ said:

Hi, I am planning on moving from Windows to Linux so have just decided to try eclipse as a visual studio alternative, but I just have a simple program at the minute, and printf isn't working (code below). I have seen posts online but not found a definite fix.

Thanks in advance.

 


#include <stdio.h>

int main()
{
	printf("hi");
	return 0;
}

 

According to my knowledge....

printf is for C programming language....ND cout is for C++ programming language.....

I guess u HV messed up..

Write this...

 

cout<<"Hi";

SSD TIER LIST

 

 

CPU - Ryzen 7 3700X

Mobo - ASRock X470 Taichi

Memory - G.Skill Trident Z RGB (8x2 3200MHz) 

Storage - Sabrent Rocket 1TB - Seagate Barracuda 2TBWD Black 1TB

GPU - MSI GeForce GTX 980Ti LIGHTNING

CaseFractal Design Meshify C

PSUSuper Flower Leadex II Gold 650W

Link to comment
Share on other sites

Link to post
Share on other sites

For c++ use iostream and cout 

#include <iostream>

using namespace std;

int main(){

 

cout << "Hello" << endl;

}

Link to comment
Share on other sites

Link to post
Share on other sites

you using eclipse. Try a better IDE. Use cin and cout. printf is C. Sure, c++ compiler can compile many C code like printf but why dont you want to use the C++ standard library?

 

#include <stdio.h>

int main()
{
	std::cout << "Hi" << std::endl;
	return 0;
}

 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

I've never like eclipse. You might want to try VS Code if your used to Visual Studio. It's not exactly an IDE, more of an editor, but it does a lot of IDE like stuff by tying in with your build environment. 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 5 weeks later...

Try using the IDE CLion instead, I don't think most people would recommend Eclipse (I've seen quite a few code issue threads on here that ended up just being Eclipse being buggy).

[Out-of-date] Want to learn how to make your own custom Windows 10 image?

 

Desktop: AMD R9 3900X | ASUS ROG Strix X570-F | Radeon RX 5700 XT | EVGA GTX 1080 SC | 32GB Trident Z Neo 3600MHz | 1TB 970 EVO | 256GB 840 EVO | 960GB Corsair Force LE | EVGA G2 850W | Phanteks P400S

Laptop: Intel M-5Y10c | Intel HD Graphics | 8GB RAM | 250GB Micron SSD | Asus UX305FA

Server 01: Intel Xeon D 1541 | ASRock Rack D1541D4I-2L2T | 32GB Hynix ECC DDR4 | 4x8TB Western Digital HDDs | 32TB Raw 16TB Usable

Server 02: Intel i7 7700K | Gigabye Z170N Gaming5 | 16GB Trident Z 3200MHz

Link to comment
Share on other sites

Link to post
Share on other sites

Have you tried to use cstdio instead of stdio.h? It is deprecated. Also, what C++ compiler do you have?

Link to comment
Share on other sites

Link to post
Share on other sites

On 01/05/2018 at 11:56 AM, Riko89 said:

using namespace std;

add this and it will work

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×