XCode compile: "undeclare use of cin" how do i fix it? - c++

I've been using Xcode 10.0 on my mac and whenever I use cin, the compiler shows an error:
|6|error: use of undeclared identifier cin|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
However, cout and other c++ built-ins are working just fine...
A few days ago I have commented out some header file in gcc's header file folder for another bug. (Is there any chance to create this problem for what I've done before with the header file folder?)

You need to
#include <iostream>
to be able to use std::cin. If you want to avoid the std:: namespace prefix, add
using std::cin;
to your code as well.

Related

GCC compiler cannot compile Hello World program [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am trying to compile the default Hello World on Code Blocks with the GNU GCC compiler but am getting the result of
cannot find -lbgi
It would be really helpful because right now I can't do a single thing!
Earlier I tried to use graphics.h and downloaded libbgi.a and I thought that was the problem so I deleted it. However, the compiler still produced the same error for the Hello World program, as well as previous programs that I made with C. From these information I guess that the problem is in the compiler but I cannot figure out what is causing it.
//c++ hello world program
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
//c hello world program
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("Hello world!\n");
return 0;
}
I expect Hello World to be the output.
however:
||=== Build: Debug in firstCppProject (compiler: GNU GCC Compiler) ===|
ld.exe||cannot find -lbgi|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
You need to create a Console application (steps).
Currently you seem to be using a project created using a template with settings for Borland-compatible graphics (using a port of the old Turbo C++ "graphics" libraries), but you have deleted the libraries required to make that work.
Alternatively, you could remove the dependency on BGI from your project's linker settings.

Cannot compile using any external libraries (Codeblocks)

I cannot compile any code using external libraries on Code::Blocks.
I tried using the boost lambda example:
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
I have a global environment variable set up for the library:
https://imgur.com/a/maiRC
...and I think I set up the build options right.
https://imgur.com/a/BP0Xk
But my build can't detect the header file:
||=== Build: Debug in boost test (compiler: GNU GCC Compiler) ===|
C:\Documents and Settings\Charlotte\My Documents\wxTest\boost test\boo.cpp|1|fatal error: boost/lambda/lambda.hpp: No such file or directory|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Unfortunately the boost include path in your first image is cut off. But it looks like
C:\Boost\include\boost-1_62\boost
Right?
That’s most likely incorrect. If you include the lambda header like you did (which is also the usual way to include a boost Header)
#include <boost/lambda/lambda.hpp>
then there needs to exist a file called
C:\Boost\include\boost-1_62\boost\boost\lambda\lambda.hpp
That does not fit the normal Boost directory layout. There is one boost too many in there. Try setting your your global environment Boost path to:
C:\Boost\include\boost-1_62

C++ Codeblocks + libcurl ends up with link errors

Hi I am a C++ beginner and I wanted to learn about http requests...
I picked cURL because I have experience using it before with php.
I downloaded this version from cURL website into C:\libs
Win64 x86_64 7zip 7.51.0 binary SSL SSH Viktor Szakáts 1.81 MB
This is what I've done so far on Codeblocks:
Under Global compiler settings/Search directories/Compiler, I added this path:
C:\libs\curl-7.51.0-win64-mingw\include\curl
Under Global compiler settings/Search directories/Linker, I added this path:
C:\libs\curl-7.51.0-win64-mingw\lib
Under Global compiler settings/Linker settings, I added this paths:
C:\libs\curl-7.51.0-win64-mingw\lib\libcurl.a
C:\libs\curl-7.51.0-win64-mingw\lib\libcurldll.a
-Under Global compiler settings/compiler settings, this box is checked from before:
Have g++ follow the C++11 standard... (no idea if this matters or not...)
Also, because I was desperate I copied the contents of C:\libs\curl-7.51.0-win64-mingw to C:\Program Files (x86)\CodeBlocks\MinGW, this step makes no sense to me, but I found it online so I tried...
Now I am running this code:
#include <cstring>
#include <string>
#include <iostream>
#include <stdio.h>
#include <curl.h>
#include <easy.h>
using namespace std;
int main(){
CURL* curl = curl_easy_init();
if(!curl){
cout << "error" << endl;
}else{
cout << "good job!" << endl;
curl_easy_cleanup(curl);
}
};
I am getting this errors:
undefined reference to `_imp__curl_easy_init'
undefined reference to `_imp__curl_easy_cleanup'
error: ld returned 1 exit status
Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s))
For some reason, including include curl/curl.h does not work, only way it works is including curl.h, same for easy.h
Any advice appreciated!
Thanks in advance!
You're linking with a static libcurl (on Windows) without having -DCURL_STATICLIB added to your CFLAGS when you build your application.
That is, you must define CURL_STATICLIB before the curl headers are included.
Described in the curl FAQ item Link errors when building libcurl on Windows

Unable to execute program using C++ IDE Codeblock GNU GCC compiler

Good evening all and thank you for any help you can provide,
I have started off on my journey of trying to learn C++ and am struggling to execute any code that I have written. I have tried using both versions 13.12 and 16.01 of Codeblock and have also tried building multiple files. Same error message appears with all. Here is the sample code I first attempted with:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello\tI am your computer talking." << endl;
return 0;
}
Here is the error message that appears when I try to build:
File Line Message
===Build: Debug in SayHello (compiler: GNU GCC Compiler) ===
1d cannot find -1pthread
=== Build failed: 1 error(s), 0 warnings(s) (0 minute (s), 0 .. second(s)) ===
Could anyone advise on a resolution? I have read conflicting solutions, such as somewhere in my computer a file is missing (1pthread?). Again, really grateful for any advice and virtual cake will follow my saviour. Thank you!
Miles

playing a .wav file

I'm using visual studio 2010 express and I'm trying to write a simple program that will repeat a wave file 5 times(I'm running a windows xp sp3).
This is as far as I got:
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
int main ()
{
int a = 5;
while(a >= 1){
cout << "It's a wav file";
PlaySound(L"SomeAudioFile-01.wav", NULL, SND_FILENAME);
--a;
}
return 0;
}
The problem is I keep getting this error message when I'm building it:
1>------ Build started: Project: It's a F**king Country, Configuration: Release Win32 -- ----
1> mycode.cpp
1>..\..\..\..\..\Shaul's documents\Visual Studio 2010\Projects\MyProject\Release\SomeAudioFile-01.wav : fatal error LNK1136: invalid or corrupt file
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The file is perfectly fine and plays with no problems whatsoever outside visual studio.
Help would be truly appreciated.
Instead of adding the WAV file to the project files, add it to the resources and use SND_RESOURCE instead of SND_FILENAME.
You include the sound file as a object file, so the compiler tries to link with it. But it's a binary file that's not linkable (which is what the error message says).
Don't include the sound file in the project, so the environment won't link with it.
P.S. In the future, please refrain from using "bad" words on a public site like this.
To get rid of the linker error, you need to tell the IDE to link with the winmm.lib library also, so open Project/Properties/Configuration Properties/Linker/Input and append winmm.lib in the Additional Dependencies field.
Also, use the following function profile:
PlaySound(L"audio.wav", NULL, SND_APPLICATION);