CPP files

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 !
First, please use code tags. That makes posted code more readable. See http://www.cplusplus.com/articles/jEywvCM9/

Second, there is no way for us to compile your code into (mal)functional program.

It seems that you read lines from one file,
IF a line starts with "Ci", THEN it becomes "City : BuseditCity"
and you write result to another file.

What is the problem that you encounter?
* Compiler error?
* Program crashes?
* Unexpected output?
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
Topic archived. No new replies allowed.