-
strlen probs
this is me code, i need strlen to recognise the sapces, how do you do this.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
char * buffer;
char tbuffer[100];
int len;
int leng;
ofstream a;
a.open("test.txt",ios::binary);
cout<<"please type a sentence > ";
cin>> tbuffer;
len=strlen(tbuffer);
a.write(tbuffer,len);
tbuffer[len]=0;
cout<< strlen(tbuffer);
cin.get();
a.close();
}
-
It's not strlen that gives you a wrong result its's the operator >> that doesn't read strings containing spaces.
You have to use getline() to read a whole line of text including spaces.
Kurt
-
can you show me an example cause i don't want to read the line i need the number of letters
-
ok i see what you are saying
cin>> won't read the spaces
use getline
cool cheers
-
but i'm using binary mode on my io,,, which doesn't recognise getline....
what should i use instead
-
dont use ios::binary leave that parameter out then try cin.getline(tbuffer);
-
what is the difference between binary and no binary LOL...
-
Basically it's just the way the end of line is handled. in textmode if you read or write a '\n' from or to the stream the '\n' is translated to whatever end of line marks your OS uses. In binary mode this translation is not done.
Kurt