i would like to have a function (actually my first one) that returns me a string.
i have some really basic questions:
1.) i know my resulting string will be 80 letters long. so the box i put it in must be 81? for the end of string thing?
2.) would this be the apropriate way to declare such a function: or is there something better than char* char* extractheaderstring(); ?
3.) lets say my string contains backslashes since its from a text file or whatever and i have no control what it contains, how do i deal with this, so i can cout the string without triggering magic backslash commands automatically?
ok i created something with string now, but im not happy yet... this surely goes easier?
1 2 3 4 5 6 7 8 9 10
{
string buffer;
char* charbuff;
for (int i = 0; i<80; i++) { // since i want 80 letters in my string
FileBin.seekp(i);
FileBin.read(charbuff,1);
buffer.append(charbuff);
}
cout <<"buffer is: "<< buffer; //checking content of buffer now...
}
You need to include <string> in-order for std::cout to understand how to handle a std::string object.
Just to clarify:
1) "String" isn't a string.
2) "String\0" is a string.
3) char* is a pointer to a character. It's not a string.
4) char *String = "String\0" is a pointer to a string literal.
ok the string include worked wonders... i didnt have it included because microsoft visual c++ 2010 "auto corrected" #include <string> to #include <specstrings.h>
now the code "magically" works but i have not really understood why and how.
i am reading a file bytewise, because it is not a .txt file. i know from the file only that the first 80 byte are unsinged chars.
i want them in a string.
getline "seems" to do the magic.
but what tells getline that it has to read 80 chars? and what must i do if i only want 40? or 10? or 200?