Q:

C++ Read/Write to textfile issue

I need to write numbers and text in a text file, for an unknown reason, the writing works, the reading does not, the problem is reading the text as in the following example:
fstream ff,ff2;
int a,b;
ff.open("simtestagain.txt",ios::out);
CString mycstring = _T("Name with spaces");
char mycharbuffer[255];         //destination buffer
size_t convertedChars = 0;      //number of characters converted
wcstombs_s( &convertedChars, mycharbuffer, mycstring.GetLength()+1,mycstring.GetBuffer(), _TRUNCATE);
ff << 1 << endl;
ff << mycharbuffer << endl; 
ff << 2 << endl;

ff.close();

ff2.open("simtestagain.txt",ios::in);

ff2 >> a;
ff2.getline(mycharbuffer,255);
mycstring = mycharbuffer;
ff2 >> b;

ff2.close();
AfxMessageBox(mycstring);

The a value is ok, the CString remains empty...

A:

The extraction operator does not consume the whitespace, so getline is just reading the whitespace that is left over on your first line.  Try adding this before your call to getline:
ff2.ignore(255, '\n');

