How to get an integer from user in c++? [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I can't get integer from user, when i try cin >> n; (where n is int variable)
it gives some strange error. Other inputs like character, double float works fine.
I was using DevC++, but now I also tried it on command line gcc, the error is still there :
undefined reference to 'std::cin'
undefined reference to `std::istream::operator>>(int&)'
...
#include<iostream>
using namespace std;
int main()
{
int n;
cin >> n;
}
it works fine if I change n to a float type or double type variable.
Tried on Bloodshed DevC++,
MinGw gcc

Try with g++ :
g++ program.cpp -o a.out
Or with gcc (If you add the c++ runtime library) :
gcc program.cpp -o a.out -lstdc++

Related

view_string MSYS2 MinGW x64 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 days ago.
Improve this question
Compiling with
g++ detect_version.cpp -o detect_version.exe
and running the following program:
int main()
{
std::cout << "Version is: " << __cplusplus;
return 0;
}
Gives me: "Version is: 201703" which is C++17 that should contain <view_string>
However if write
#include <view_string>
It gives me:
detect_version.cpp:3:10: fatal error: view_string: No such file or directory
3 | #include <view_string>
| ^~~~~~~~~~~~~
compilation terminated.
Under MSYS2 MinGW libstdc++ should be mingw-w64-x86_64-gcc-libs and from that I do have the latest version:
$ pacman -Q | grep mingw-w64-x86_64-gcc-libs
mingw-w64-x86_64-gcc-libs 12.2.0-10
What could be the problem?

how to link a c++ library to a c++ source code when it has a specific linker script to compile? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
i have these files:-
/lib
kernel.hpp
kernel.cpp
main.cpp
when i use
gcc -m32 -c main.cpp -lstdc++ -o main.o -llib/kernel.hpp
it says
[function name]([type of argument 1], [type of argument 2]) is not declared in this scope
how to fix?
I started writing a comment, but got to be too long, so we'll make it an answer instead. I don't think it in fact will answer your question, but it may point you in the right direction.
Let's clear up a misconception, c++ is not a superset of c; there are c constructs that c++ does not support. If your code is c++, you need to compile it with a c++ compiler. The problems you've been describing all indicate that compilation is failing; you're not at the point where the linker is involved. The compile command you provided in your question had a -c flag, which tells the compiler to stop after the compilation step - so there's no point in having a -lstd++ flag in addition. For the compiler to find kernel.hpp you need a -I flag which indicates the directory where kernel.hpp can be found. That's what I was suggesting in my first comment.
To sum up, as shown in the original question, you're using the wrong compiler and the wrong flags for what you want to do.

a.exe: file not recognized: File truncated [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
It was working perfectly for others c file but in this file it fail to run . Please do explain , as i am new to Programming world.
C:\Desktop\C Basic\recursiveFunction> gcc .\pratice.c
PS C:\Desktop\C Basic\recursiveFunction> gcc .\a.exe
.\a.exe: file not recognized: File truncated
collect2.exe: error: ld returned 1 exit status
gcc is the compiler. You compile your program using gcc .\pratice.c. You can remove the .\ since gcc will look in the current directory for source files anyway.
You execute your compiled program using .\a.exe.

cout not printing to terminal screen C++ [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm running a .cpp file and trying to print out to the screen for debugging purposes, however my message does not appear. I'm running my program from the Linux Terminal using the following command:
g++ -m32 -static genConfig.cpp -o genConfig
All that my .cpp file should do at this point is cout to the terminal as show below. However the output doesn't appear.
#include <string>
using namespace std;
int main(int argc, char ** argv) {
cout<<"HEYYYA";
}
The command g++ -m32 -static genConfig.cpp -o genConfig does not run the application, it compiles (and links) it. In order to run the generated binary, you need to execute ./genConfig.
Also, you need #include <iostream> and actually #include <string> is not needed (at least not for this specific portion of code).

unistd : no such file or directory [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have the following test.cpp file :
#include <unistd>
int main()
{
return 0;
}
I just want to compile this but I still have the following :
$ g++ test.cpp
test.cpp:1:18: fatal error: unistd: No such file or directory
#include <unistd>
^
compilation terminated.
I found unistd.h at /usr/include/unistd.h. and my $LD_LIBRARY_PATH environment variable was empty so I set it at /usr/include (with export LD_LIBRARY_PATH=/usr/include) but the problem remains.
What could I do?
The name of the header is unistd.h, not unistd. And LD_LIBRARY_PATH is used to locate shared libraries, not header files.