HelloWorld C++: mysterious request to access desktop folder - c++

Following instructions here, I built and executed the following code under Mac OS 11.6 and VS code 1.61.2. Code unmodified from
https://code.visualstudio.com/docs/cpp/config-clang-mac
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg) {
cout << word << " ";
}
cout << endl;
}
When it executes, Mac OS pops up with the following unexpected question:
"helloworld wants permission to access files on the desktop." When denied, the program exited without complaint and without output. When executed directly from the command line, helloworld prints the expected output and does not show the strange behavior.
What the heck? I touched no files! Is my C++ library corrupted with malware? Has anyone else seen this odd behavior?
I finally said yes and it quit asking. Should I change my mind? And where would I go to do so?

Thank you, Alan Birtles, moving its grandparent folder off the desktop to another location solved the message and more.

Related

Console doesn't show output from vector

I have a weird problem when trying to print out the content of a vector.
I'm using Visual Studio Code with the CMake extension.
I can print out simple text using cout
#include <iostream>
#include <vector>
using namespace std;
int main() {
cout << "test" << endl;
return 0;
}
But I can't print out the vectors content
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> test = {1,2,3};
cout << "test" << endl;
cout << test[1] << endl;
return 0;
}
I've never really worked with C++ vectors, so I'm probably missing something fairly obvious but I followed a C++ vector tutorial step by step and for them, the output works fine.
Cheers,
Luca
I'm new to C++ and have exactly the same problem.
Temporary workaround as posted by Luckylone here
would be to copy libstdc++-6.dll from your mingw64\bin folder into your project folder.
Something is messing up our link with the resources even though folders are properly added to system PATH.
EDIT: After an afternoon of troubleshooting, I've solved my problem by uninstalling compilers (originally provided through WinLibs) and reinstalling them using MSYS2.
Delete the existing Mingw64 folder, remove the PATH variables, then carefully follow these instructions. Keep in mind that I had to add mingw64/bin to both user and system Path, and restart VS Code before damn std::vector finally started to print.

getline(ifstream, string) on Mac causes EXC_BAD_ACCESS

I've been a C++ developer since it arrived. All was on windows, and I haven't touched it in about 6 years.
Now I'm trying to get an old code-base working using VS Code on my Mac. I'm using clang++ with c++17.
This problem is vexing; I've seen many other posts with the same issue, but the problem always seemed to be something in the code.
Note: this code worked fine with C++11 on Windows.
To simplify, I copied the code to execute right at the top of main. Here is is:
ifstream file("assets/textures/blocks.txt", ios::in);
if( file.is_open() ) {
string s;
getline(file, s); // <-- This line causes the error.
cout << s << endl;
}
As this code worked elsewhere, I assume I've got a setup or environment problem and am looking for hints towards what to check on.
Thank you for any help!
An update:
Thank you. I paired the program down and tried a few things. Here's the deal:
If I leave all my files to be compiled, but replace main.cpp with the below code, the cout line generates the same exception.
If I cull all the unused files, the code works.
Something in some other file is somehow breaking the stream code. I'm clueless.
#include <iostream>
#include <istream>
using namespace std;
int main() // int argc, char** argv)
{
cout << "Hello World" << endl;
}
I should add: this is a GLFW 3D game engine app. It does not subclass or interact with any stream in any way other than the most basic file read/write operations.

When the program built with C::B doesn't work

I made a small c++ project and it was fully compiled and built it.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
When I run through c::b it was okay
However, it says next warnings when I run program outside of the c::b.
"programdir/bin/Debug/program.exe"
So I got "libgcc_s_dw2-1.dll" from sourceforge, pasted it next to my .exe file,
and I got 0xc000007b error with the error "cannot start the program"
What should I do in this case of problem?

Microsoft visual studio 2012 c++

I am learning c++ from scratch and I was trying to make hello world program with this code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
but I always end with "this project is out of date"
and when I try to build it I have this error message:
unable to start program 'c:\users\User\documents\visualstudio2012\projects\Consoleapplication3\Debug\ConsoleApplication3.exe'.
the system cannot find the file specified
Your program should fail if you do not include your default #include <iostream>, which implies that your code should be something like this:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
These said, to fix your problem, look in the solution explorer box to the left. Make sure that there is actually a .cpp file there. You can do the same by looking the .cpp file where the .sln file for the project is stored. If there is not one, then you will get that error.
When adding a cpp file you want to use the "add new item" icon. (top left with a gold star on it, hover over it to see the name) For some reason Ctrl+N does not actually add a .cpp file to the project.
Sources : System cannot find specified file

C++/Eclipse CDT code completion problem (Wascana,mingw)

I've a problem with my CDT. Code completion doesn't work for standard library classes.
For example in this code after entering x. and presing ctrl+space IDE doesn't display the list of API elements.
#include
void f() {
string x = "sss";
x.
}
String and vector header files are available in Includes directories. When I press ctrl+click on the include line I'm redirected to header file.
Code completion seems to work fine for C std library.
My version of eclipse:
Eclipse IDE for C/C++ Developers
Version: Helios Release
Build id: 20100617-1415
Eclipse C/C++ Development Tools
Version: 7.0.0.201006141710
Build id: 201006141710
Please help.
Try this:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("Test string");
cout << "The size of str is " << str.size() << " characters.\n";
return 0;
}
first: check whether it compiles, then place cursor before "return" and try code assist: "str." and see if it pops up.