Re: [Dev-C++] newbie Parsing strings
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: P.D. v. Z. <pd...@xs...> - 2004-07-27 20:12:07
|
Or like this (who needs a counter when the vector class manages
everything itself, and when we have iterators):
ifstream in("somefile.txt");
vector<string> address;
while (getline(in, address))
address.push_back();
for (address::const_iterator it = address.begin(); it != address.end();
++it)
{
cout << *it << endl;
}
Scott Simontis wrote:
> Like this:
> ifstream in("somefile.txt");
> vector<string>address;
> int vectorcount;
>
> while( getline( in, address ) )
> {
> address.push_back();
> vectorcount++;
> }
>
> And to print the information:
> for( vectorcount; vectorcount > 0; vectorcount-- )
> {
> cout << address[vectorcount];
> }
>
> This method uses vectors, so make sure you include <vector> For more
> information, look for STL references.
|