i have too many files open?

I keep getting this error msg and I don't get why

// open input file
ifstream fin; //
fin.open (usersFile.c_str()); //
if (!fin.good()) throw "I/O error"; //

// open output file
ofstream fout;
fout.open ("secret.txt");
if (!fout.good()) throw "I/O error" ; //

//input line
while (fin.good())
{
getline(fin, usersFile);

// encode string s by adding 1 to the ASCII code of each character
for (i = 0; i < codedMsg.length(); i=i+1)
{
codedMsg[i] = codedMsg[i] + 1; // bump the ASCII code by 1
}//for i

//the result
cout << codedMsg <<endl;
fout << codedMsg <<endl;
}

Put the code you need help with here.
lab2.cpp:63:30: error: request for member 'length' in 'codedMsg', which is of non-class type 'std::string()' {aka 'std::__cxx11::basic_string<char>()'}
63 | for (i = 0; i < codedMsg.length(); i=i+1)
| ^~~~~~
lab2.cpp:65:17: warning: pointer to a function used in arithmetic [-Wpointer-arith]
65 | codedMsg[i] = codedMsg[i] + 1; // bump the ASCII code by 1
| ^
lab2.cpp:65:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
65 | codedMsg[i] = codedMsg[i] + 1; // bump the ASCII code by 1
| ^
lab2.cpp:65:33: warning: pointer to a function used in arithmetic [-Wpointer-arith]
65 | codedMsg[i] = codedMsg[i] + 1; // bump the ASCII code by 1
| ~~~~~~~~~~~~^~~
lab2.cpp:65:19: error: assignment of read-only location '*(codedMsg + ((sizetype)i))'
65 | codedMsg[i] = codedMsg[i] + 1; // bump the ASCII code by 1
Put code in code tags to preserve indentation.

I don't know why you think you have too many files open.
It looks like you've defined codedMsg incorrectly, but you haven't shown that part.
you were right I defined codedMsg wrong.
Topic archived. No new replies allowed.