W
William Payne
Hello, consider the following code:
#include <iostream>
#include <string>
void foo(std::string& s);
int main()
{
const char* directory = "c:\\blah";
std::string s = directory;
foo(s);
foo(s);
std::cout << s << std::endl;
return 0;
}
void foo(std::string& s)
{
if(*(s.end()) != '\\')
{
s += '\\';
}
}
When I run that, the program outputs:
c:\blah\\
I thought (and need it to be) would be:
c:\blah\
What am I doing wrong?
/ William Payne
#include <iostream>
#include <string>
void foo(std::string& s);
int main()
{
const char* directory = "c:\\blah";
std::string s = directory;
foo(s);
foo(s);
std::cout << s << std::endl;
return 0;
}
void foo(std::string& s)
{
if(*(s.end()) != '\\')
{
s += '\\';
}
}
When I run that, the program outputs:
c:\blah\\
I thought (and need it to be) would be:
c:\blah\
What am I doing wrong?
/ William Payne