Sign in to follow this  

Declaring std::String Causing Segfault

This topic is 1202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites

This topic is 1202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this