Can someone explain what is happening here?
#include <iostream>
#include <string>
using namespace std;
int main() {
string kek = "kek";
cout << "test" << endl;
return 0;
}
For some reason, every time I compile with g++, and I declare a string variable, I can't see any output, no compile or runtime errors, simply no output.
Now, if I change the code to be this instead:
#include <iostream>
#include <string>
using namespace std;
int main() {
// string kek = "kek";
cout << "test" << endl;
return 0;
}
then everything works.
Does anyone know what the problem is here?
I am currently on Windows 10, using gcc 8.1.0.
Edit:
same thing but using bash, linux compile
i think the version of mingw i had is bugged so trying to reinstall it
Okay so still i have no idea what that bug was about,
but when i had it, the version of MinGW i had was 32bit,
changing the MinGW installation to 64bit, fixed that issue.
i have changed nothing, except removing MinGW 32bit from my comp,
and setting the MinGW 64bit.
Swaping from MinGW 32bit to 64bit, fixed the issue.
Related
unable to compile even the hello world programe
#include <iostream>
using namespace std;
int main(){
cout <<"hello world";
system("pause");
return 0;
}
Dev ++ clearly compiles to 16 bit architectures and they are deprecated and unsupported since exactly Windows Vista. So you clearly have to use a different compiler.
I constantly have CLion editor showing me parameter type mismatch errors while during build everything is fine. For example, consider the following MWE:
#include <iostream>
#include <boost/container/flat_set.hpp>
using namespace std;
namespace bc = boost::container;
int main() {
bc::flat_set<bc::flat_set<int>> manySets;
bc::flat_set<int> oneSet({1, 2, 3});
manySets.insert(oneSet);
cout << "Hello, World!" << endl;
return 0;
}
Here flat_set is a template from boost library (description could be seen here). Editor shows me an error:
But when I build it (even from CLion), everything is compiled fine.
My system is:
Ubuntu 15.10 64bit
CLion 1.2.4
This looks like a known problem - https://youtrack.jetbrains.com/issue/CPP-6027. We hope to fix it soon.
#include <iostream>
#include <string>
using namespace std;
int main(){
string s = "wassup", newVal = "though";
cout << *(s.insert(s.begin(), newVal.begin(), newVal.end()));
}
This brings up the problem that the return type of string's insert member function is void (error: void value not ignored as it ought to be). This link indicates C++98 returns void but the "new" standard C++11 does indeed return an iterator.
A bit of context, I actually faced this problem earlier. I was/am using CodeBlocks (GCC Compiler Collection) on Windows 7 64-bit and this program gave the same issue (dereferencing void):
#include <iostream>
#include <list>
int main(){
list<int> x = {1,2,3,4};
*(x.insert(++x.begin(), 3, 2));
for(auto c : x)
cout << c;
}
I posted my issue on a different forum and a user pointed out Mingw32 was missing that particular C++11 change, indicating Mingw-w64 does not have this issue. So I went straight to installing Mingw-w64 on Code::Blocks using this guide and the problem was resolved. It's only now I've found out that the overloaded function which takes three iterator parameters STILL returns void.
I'm a little confused as to why Code::Blocks Mingw32 didn't supply a fully updated C++11 standard. Can anyone suggest a download that will definitely bring my compiler up to speed?
When I compile the code:
#include <iostream>
#include <string.h>
using namespace std;
int main(void) {
string m1;
cout<< "enter your name: "<<endl;
getline(cin,m1);
cout << "Your name is: " << m1 << endl;
return EXIT_SUCCESS;
}
It give the following warning:
type of symbol `_main' changed from 32 to 512 in >C:\Users\KDesktop\AppData\Local\Temp\cc7XPBuL.o
Secondly, the compiler does generate an .exe file, but whenever I run it, the program crashes immediately. Can someone help me with this issue.
Thank you
Your toolchain is outdated. Older versions of LLVM used the wrong value for the function symbol type; the bug was fixed in late 2010. Here's the bug report: http://llvm.org/bugs/show_bug.cgi?id=8320
You should upgrade your LLVM; the problem will go away.
Here is some code that used to work with my code, but is having a problem now:
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
using namespace std;
int main()
{
stringstream out;
out << 100;
cout << out.str();
}
I get just blank output. I just changed to snow leopard with Xcode 3.2.
Get this exact same issue under the same conditions Snow Leopard 64-Bit XCode 3.2 Base SDK 10.6 and the switch to Base SDK 10.5 resolves it.
Apparently it's a SDK 10.6 issue.
and the correct workaround is to remove the preprocessor macros:
_GLIBCXX_DEBUG=1
_GLIBCXX_DEBUG_PEDANTIC=1
From the preprocessor settings (or else fall back to SDK 10.5 as above).
Apple Discussion Link
it works for me. if there's a problem, it should be your gcc's.
btw, maybe you have to add fflush(stdout); after the cout << sometime the problem is stdout buffer
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
using namespace std;
int main()
{
stringstream out;
out << 100;
cout << out.str();
fflush(stdout);
}
Another idea is that you have a .o file left over from before you upgraded that's somehow messing things up. Mixing .o files from two different versions of the C++ compiler can cause all kinds of strange problems. I also do not discount the header file issue as well, though sstream should be including string.
Shouldn't you add the end of string before converting to string?
cout << out.str() << sdt::ends;