I'm following some C++ tutorials and have started experimenting with structures, however a test structure I built is not behaving as intended. I have tried running it a few times and all it outputs is (11db), and when I try rerunning it I get a window saying that the product is already running.
Here is the code...
#include <iostream>
using namespace std;
int main(){
struct Address {
int streetNum;
string streetName;
};
Address myHouse;
myHouse.streetNum = 911;
myHouse.streetName = "Inverness Street";
cout << myHouse.streetName << endl;
return 0;
}
I would expect the output to be "Inverness Street". Why am I getting an error instead?
EDIT ** Bonus points for anyone who can tell me how to remove a missing file warning? I removed a useless file that was created as a means to find my way around creating different types of files, but since I deleted it I have had a warning in the file that it once shared a folder with.
Related
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.
I'm getting started with C++ and am trying to work with vectors and printing stuff. I am using Windows 10, writing my code in Visual Studio Code, I just downloaded the MinGW-g++ compiler, and am trying to run my code in CMD.
This is my code, I've tried printing different things, and it's not even printing this "Hello". I've also tried using << endl; which also prints nothing. I also tried adding and remove a "return 0;" at the end but it changed nothing. The program compiles just fine. Any advice?
#include <iostream>
using namespace std;
int main(void)
{
std::cout << "Hello";
std::cout.flush();
}
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.
So I am a novice C++ programmer, and have never coded anything on MacOS. Currently I am using Xcode 6 Beta 3 and I am getting an unusable variable error whenever I want to name a variable to an integer.
my setup looks like this
#include <iostream>
using namespace std;
int main ()
{
int a;
cout << "Hello World!" << endl;
return 0;
}
I am getting a warning sign beside the int a; saying that it is an unusable variable. Why is that?
Also because that is such a novice question perhaps you could direct me to some solid Xcode 6 tutorials that would teach me how to code in the command line.
I finally was able to get Lua running with my compiler using C++. I now tried starting some tutorials and the first program won't do anything. I downloaded the code they used and it still did nothing. No errors however. Test prints out fine but I get no response from the luaL_dostring. I am using v5.1.4-46. Is it possible that i installed it incorrectly in some way that doesn't result in errors? I printed out the memory address of the lua state and that seems to be working. If someone could give me some sample code to run I would really appreciate it.
Here's the code:
#include <lua.hpp>
#include <iostream>
#include <string>
using namespace std;
int main()
{
lua_State *L = lua_open();
luaL_openlibs(L);
cout << "Test" << endl;
luaL_dostring(L, "print(\"Hello from Lua!\n\")");
lua_close(L);
return 0;
}
Your dostring syntax generates invalid Lua code... "\n" gets passed to lua parser before execution. you need a "\\n"... think so. So your "luaL_dostring" error code is actually a syntax fault. funny thing...
you should not use dostring for more than testing.