Advertisement

Declaring std::String Causing Segfault

Started by August 26, 2014 04:55 PM
2 comments, last by AoS 10 years, 5 months ago

I have a project in Code::Blocks to practice my SDL. For some reason something as simple as this:

string stringname;

is causing a segfault for me. I don't ever recall having an issue where declaring a string caused this.

I generated an all new console project to test this:

#include <iostream>
#include <string>
using namespace std;
using std::string;
int main()
{
std::string helloworld = "hello world";
cout << helloworld << endl;
return 0;
}

This has the same issue. Am I just missing something obvious?

No you aren't. There is nothing in the posted code that would segfault (your using std::string is redundant but that is all).

Something is screwy with your machine or installation. Are you maybe building a 64 bit app for 32 bit windows? Does the program not segfault if you remove the string stuff and just cout a string literal?
Advertisement

I have a project in Code::Blocks to practice my SDL. For some reason something as simple as this:

string stringname;

is causing a segfault for me. I don't ever recall having an issue where declaring a string caused this.

I generated an all new console project to test this:

#include <iostream>
#include <string>
using namespace std;
using std::string;
int main()
{
std::string helloworld = "hello world";
cout << helloworld << endl;
return 0;
}

This has the same issue. Am I just missing something obvious?

As Aardvajk pointed out it is your installation. You need to install Code::Blocks again. Also as pointed out if you are doing 'using namespace std;' you don't need 'using std::string;' and you don't need 'std::' on the line definition of helloworld.

I have a project in Code::Blocks to practice my SDL. For some reason something as simple as this:

string stringname;

is causing a segfault for me. I don't ever recall having an issue where declaring a string caused this.

I generated an all new console project to test this:

#include <iostream>
#include <string>
using namespace std;
using std::string;
int main()
{
std::string helloworld = "hello world";
cout << helloworld << endl;
return 0;
}

This has the same issue. Am I just missing something obvious?

As Aardvajk pointed out it is your installation. You need to install Code::Blocks again. Also as pointed out if you are doing 'using namespace std;' you don't need 'using std::string;' and you don't need 'std::' on the line definition of helloworld.

Yeah, I worked it out in the site chat with SotL that my installation was messed up somehow. Still no idea why. Didn't do anything different on the second install.

This topic is closed to new replies.

Advertisement