B
Billy N. Patton
-------- Original Message --------
Subject: <string>.replace
Date: Fri, 15 Oct 2004 11:07:19 -0500
From: Billy N. Patton <[email protected]>
Organization: Texas Instruments
Newsgroups: alt.comp.lang.learn.c-c++
I'm trying to remove the \n from a string.
If I just simply locate teh char and replace it with \0 then the
destructor should only delete up to the \0 and leave 1 char unrecovered.
Here is what I've tried several times
From my documentation
basic_string &replace( size_type index, size_type num, const
basic_string &str );
bool ExCommand(string& cmd,vector<string>& ret)
{
string s;
static char buf[BUFSZ];
FILE *ptr = NULL;
if (cmd.empty()) return false;
if ((ptr = popen(cmd.c_str(), "r")) NE NULL)
{
while (fgets(buf, BUFSZ, ptr) NE NULL)
{
s = buf;
s.replace(s.length()-1,1,"\n");
cout << "'" << s << "'\n";
ret.push_back(s);
}
pclose(ptr);
}
else
{
return false;
}
return true;
}
The cout prints :
'./TEST.cxx
'
It's not replacing the \n
I've tried s.length() without the -1 with the same results.
--
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455, (e-mail address removed)
--
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455, (e-mail address removed)
Subject: <string>.replace
Date: Fri, 15 Oct 2004 11:07:19 -0500
From: Billy N. Patton <[email protected]>
Organization: Texas Instruments
Newsgroups: alt.comp.lang.learn.c-c++
I'm trying to remove the \n from a string.
If I just simply locate teh char and replace it with \0 then the
destructor should only delete up to the \0 and leave 1 char unrecovered.
Here is what I've tried several times
From my documentation
basic_string &replace( size_type index, size_type num, const
basic_string &str );
bool ExCommand(string& cmd,vector<string>& ret)
{
string s;
static char buf[BUFSZ];
FILE *ptr = NULL;
if (cmd.empty()) return false;
if ((ptr = popen(cmd.c_str(), "r")) NE NULL)
{
while (fgets(buf, BUFSZ, ptr) NE NULL)
{
s = buf;
s.replace(s.length()-1,1,"\n");
cout << "'" << s << "'\n";
ret.push_back(s);
}
pclose(ptr);
}
else
{
return false;
}
return true;
}
The cout prints :
'./TEST.cxx
'
It's not replacing the \n
I've tried s.length() without the -1 with the same results.
--
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455, (e-mail address removed)
--
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455, (e-mail address removed)