• Advertisement
Sign in to follow this  

C_str error

This topic is 2775 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

When I try to compile this:

void copy(int a){
stringstream profile;
char profilepath[50];
ExpandEnvironmentStrings("%userprofile%",profilepath,250);
profile <<"xcopy " << profilepath << "/appdata/roaming/.minecraft/saves/world" << a << " /world" << a << "/s";
system(profile.c_str());
cout << "Copied files successfully. Press any key to exit";
getch();
GameRunning = false;
}

I get
Quote:
1>c:\badprogramer\minecraft helper\minecraft helper\main.cpp(60) : error C2039: 'c_str' : is not a member of 'std::basic_stringstream<_Elem,_Traits,_Alloc>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Alloc=std::allocator<char>
1> ]

I am trying to make a program that copies files, but this has set me back. Help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
stringstream can only give you an std::string, so it should be:

system(profile.str().c_str());

Share this post


Link to post
Share on other sites
c_str is a member of std::string, not std::stringstream.

You want to write profile.str().c_str(), which first gets a string from the string-stream, and then gets a c-string from the string.

[edit]Ninja'd =)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement