Using "string" header file gives error in c++ on Windows 10 - c++

So I recently upgraded Windows 8.1 to Windows 10. I didn't faced this type of error before but when I program in c++ and include "string" header file then it pops out an error when executing though compiling does not give any error. I tried using "cstring" and update Microsoft Visual C++ Redistributable but no change. If I don't use "string" header file then it will not produce any error.
Here is test.cpp
#include <iostream>
#include <string>
using namespace std;
int main(){
string text = "Hello World!";
cout << text;
return 0;
}
On compiling it does not give error
g++ test.cpp -o test.exe
But when I tried to execute via console it doesn't print anything.
And when I tried to execute by double clicking "test.exe" then it showed me this

Finally I found what causes this error.
There was a faulty app which is set in my system path variable containing a faulty libstdc++-6.dll which causes this error. I remove the path from th system path variable and now everything working fine.

Related

C++ programming not compiling <iostream>

I'm beginning to learn C++ programming, I'm using the visual studio editor.
This is the simple code I entered:
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
cout << "Hello, comply";
return 0;
}
I only added the "#include iostream" because my textbook says that is needed to let the program output to screen. I tried to compile and run in my command prompt and its giving me some error:
**C:\Users\edika\Desktop>gcc comply.c -o comply.exe
comply.c:2:22: fatal error: iostream: No such file or directory
#include <iostream>
^
compilation terminated.**
What am I doing wrong?
you're using a C compiler for C++. Additionally, your file extension should be *.cpp to indicate C++ code.
You're using gcc, you need g++.
Install G++, change your file name to comply.cpp, then run "g++ comply.cpp -o comply.exe"

[C++ Library]: "file or folder does not exist" when compiling

I want to develop a small application which uses some libraries. So I downloaded them and placed the include files in a folder called include.
For my application, I used cpprestsdk, but my question shouldn't be limited only to this library.
This is a rough example of my folder Structure:
myproject
include
cpprest
...
pplx
...
test.cpp
And this is my Code:
#include <iostream>
#include "include/cpprest/http_client.h"
#include "include/cpprest/filestream.h"
#include "include/cpprest/json.h"
int main() {
// code
std::cout << "Hello World!";
return 0;
}
which results in followin error code when compiling (g++ test.cpp -o test) with g++ or gcc (on Ubuntu):
<error needed>
What have I done wrong? when I inspect the file mentioned in the error message, then I notice, that all includes in the library are like so #include "cpprest/asyncrt_utils.h". As you can see, it refers to the file as it were in a subfolder called cpprest, which it is not. It is located with the other file in the same folder. I guess that results in my problem. My question now is: how do I fixe this issue?

fatal error C1083 during build of program to test CStrings

I am trying to explore the CString Data type which is used extensively in my company's test program.
Here is the code:
#include <iostream>
#include <string>
#include <afx.h>
using namespace std;
int main()
{
CString cs("meow");
wcout << cs << endl;
return 0;
}
The above code compiles with 0 errors. However, when I try to build it, I get the following error.
fatal error C1083: Cannot open include file: 'atlstr': No such file or directory
I am using Visual C++ 6 Standard Edition for development.
Please note that my company's test program can compile and run well and I don't get the aforementioned error.
Is there a place where I can download the atlstr include file?

C++ Quantlib EXC_BAD_ACCESS in Xcode

I've been trying to run some of the example code (BermudanSwaption) in Xcode but keep getting an EXC_BAD_ACCESS code=2.
But compiling and running the BermudanSwaption code in the terminal works correctly.
The following code throws the same error in Xcode.
#include <ql/quantlib.hpp>
#include <iostream>
using namespace QuantLib;
int main (){
Date date(18, March, 2014);
std::cout << date << std::endl;
}
And this runs correctly.
g++ -I/opt/local/include/ -I/opt/local/include/boost main.cpp -o main -L/opt/local/lib/ -lQuantLib
Are there some specific settings I need to tweak in Xcode in order for this to run?
I found that #including the individual libraries separately rather then including ql/quanlib to work. So in my example sub ql/quantlib.hpp with ql/time/date.hpp and everything runs fine.
Following the suggestion of Kaush, and a bit of trial and error, the following works for me in QuantLib 1.4, and means you don't have to add in every single individual library:
In <ql/experimental/models/all.hpp>, comment out these lines:
#include <ql/experimental/models/kahalesmilesection.hpp>
#include <ql/experimental/models/markovfunctional.hpp>

Trying to set up the GNU C++ COMPILER, but I get an error I don't understand when I try to compile hello.cpp

So I bought this book called C++ Programming In Easy Steps by Mike McGrath online.
In the instructions it specifies to create a source file written in C++, the infamous "helo world". So I created my cpp file through sublime text editor and moved it to a file called MyPrograms in my C directory.
The code is as follows:
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "hello world"<< endl ;
return 0 ;
}
I have also tried:
#include
using namespace std;
int main()
{
cout << "hello world"<< endl ;
return 0 ;
}
Ok so I saved this file as hello.cpp in C:\MyPrograms.
Then here is where the error occurs....
I open cmd.
I do "c++"
I receive the message "c++: no input files".Which is what I'm supposed to recieve according to the book.
I proceed to do "cd\myprograms" to enter into the MyPrograms directory.
Once in that directory I do "c++ hello.cpp". According to the book this is supposed to compile my source file and create an executable file next to it. Instead I get a long error message that end in collect 2: 1d returned 1 exit status.
When I visit MyPrograms no executable file has been made next to the original cpp file.
I have also tried to do "c++ hello.cpp -o hello.exe" but it gives me the error again. All of this is done on the command prompt.
Please help :(
It looks to me like MinGW isn't installed properly.
First, it looks like you are trying to use version 4.0.3 but it may be conflicting with a version 3.4.5 that you installed previously (one in c:\mingw and the other in e:\p\giaw\src\pkg).
The latest version of MinGW is 4.7.2.1 which you can install from here: http://www.mingw.org/wiki/InstallationHOWTOforMinGW
But it looks like you're just starting out and it may be better to work with something that's better optimized for Windows (unless you're trying to compile Free Software). You can get a copy of Visual Studio Express for free here:
http://www.visualstudio.com/downloads/download-visual-studio-vs#d-express-windows-desktop
There are older versions available as well if you scroll down (VSE 2010).