Jan 24, 2020 at 3:28pm UTC
hello all,
i wondring where am i wrong.
i'm trying to edit a file line, meaning replace one line with another one.
this is my program ->
fs.open(filename, std::fstream::in | std::fstream::out | std::fstream::app);
if (!fs)
{
MessageBox(L"no file found");
}
while (std::getline(fs, str))
{
//while ((pos = line.find(replace, pos)) != std::string::npos) {
// line.replace(pos, line.size(), replace_with);
// pos += replace_with.size();
if (str[i] == 'C' && str[i+1] == 'i')
{
CString theCStr = BuseditCity;
string toString(CW2A(theCStr.GetString()));
string towrite = "City : " + toString;
str.replace(0, str.size(), towrite);
fs1 << towrite << endl;
}
else
fs1 << str <<endl;
//MessageBox(L"find");
}
many thanks !
Jan 24, 2020 at 4:07pm UTC
what is the value of i in str[i] and str[i+1] when the line is blank?
Actually, where is i even defined or set??
can you use code tags <> on the editor to make it readable?
should you just use strstr or find() on this thing?
eg
if(strstr(str, "Ci"))
{}
Last edited on Jan 24, 2020 at 4:09pm UTC