I need to read a specific number of characters into an std::string
from a file regardless of the characters read.
* fstream operator>stops when it runs into a white space character.
* The global variant of fstream::getline works with std:string but
does not take a 'width' parameter.
* ifstream::get takes a 'width' parameter but does not work with
std::string.
I simply want to read a specific number of characters and only stop on
EOF. Is there any straight forward way to do it ? 8 4264
Resize the string first, and rely on the fact that in all (known) current
implementations it has contiguous buffer, and that will be guaranteed in C++0x.
I think std:string automatically accommodates input from operator>>.
am I missing something ?
Cheers, & hth.,
- Alf
kh*******@gmail.com wrote:
>Resize the string first, and rely on the fact that in all (known) current implementations it has contiguous buffer, and that will be guaranteed in C++0x.
I think std:string automatically accommodates input from operator>>.
am I missing something ?
I think Alf was telling you to do an unformatted read directly into the
string's buffer.
--
Ian Collins.
On Aug 9, 1:44*am, Ian Collins <ian-n...@hotmail.comwrote:
I think Alf was telling you to do an unformatted read directly into the
string's buffer.
What's the API for that, std::string has data() and c_str(), and both
return a const char* which can't/shouldn't be modified.
The only solution I could think of, is to create a custom stream class
over cstdio ... C streams seem to be more mature. kh*******@gmail.com wrote:
On Aug 9, 1:44 am, Ian Collins <ian-n...@hotmail.comwrote:
>I think Alf was telling you to do an unformatted read directly into the string's buffer.
What's the API for that, std::string has data() and c_str(), and both
return a const char* which can't/shouldn't be modified.
&string[0]
--
Ian Collins. kh*******@gmail.com wrote:
The only solution I could think of, is to create a custom stream class
over cstdio ... C streams seem to be more mature.
std::string buffer(width, ' ');
inputFile.read(&buffer[0], width);
What's so hard about that?
On Aug 9, 11:48*am, Juha Nieminen <nos...@thanks.invalidwrote:
* What's so hard about that?
Nothing, just never crossed my mind, thanks :)
On Aug 9, 11:03*am, Ian Collins <ian-n...@hotmail.comwrote:
&string[0]
Yeah, thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Armando |
last post by:
Hallo !
I habe some error in my programm,because i use <fstream.h>,I want to
use <fstream> but i don´t know which fonctions i must modify in my
program ?
Thanks you for your help.
Armando.
|
by: David Briggs |
last post by:
I am using MS VC++ 6.0 with MFC
I have a simple class:
#include <fstream.h>
class Data
{
public:
CString WriteStr();
Data();
|
by: Macca |
last post by:
Hi,
I have been using <fstream.h> in stdafx.h,(i'm using MFC) to output to
text files. I have now started to use vectors and when i added
#include <vector>
using namespace std;
to...
|
by: nils |
last post by:
Hi all,
Recently I started migrating a gcc project to Visual Studio C++ (dotnet).
The problem is that I cannot include any iostream header-file:
#include <fstream>
int main (int argc, char *...
|
by: Falos425 |
last post by:
Okay, I've got a driver.cpp, a section.cpp, and a section.h because
I've got a 'section' class.
I have an #include <fstream> in the section.h and then section.cpp has
an #include "section.h"
...
|
by: adamrobillard |
last post by:
Hi,
I have always used fopen and FILE* to load and save structures to file.
I am trying to convert all the older code to use proper C++ calls...
the following code works properly but I would...
|
by: Noah Roberts |
last post by:
template < typename T >
std::istream & operator >(std::istream & in, std::pair<T,T& p)
{
in >p.first >p.second;
return in;
}
....
std::istream_iterator< std::pair<size_type, size_type
|
by: neowillis |
last post by:
code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
|
by: puzzlecracker |
last post by:
Say we have this structure:
Struct Foo{
....
friend ostream& operator << (ostream& s, Foo & m);
.....
};
friend ostream& operator << (ostream& s, Foo & m){
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |