C++.......as stated above...thanks for any answer
How to know the total number of items from external file by using array and function
Started by kuang, Sep 28 2010 11:46 PM
5 replies to this topic
#1
Posted 28 September 2010 - 11:46 PM
|
|
|
#2
Posted 29 September 2010 - 02:23 AM
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
ifstream file( "items.txt" ) ;
string line ;
vector<string> lines ;
while( getline( file, line ) ) lines.push_back( line ) ;
cout << "#items: " << lines.size() << '\n' ;
}
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 29 September 2010 - 06:11 PM
if i don want to use string and vector?becauce we not yet learn vector
#4
Posted 30 September 2010 - 10:16 AM
Just input each "item" into a variable, increment a counter, and loop through that until EOF is found.
Latinamne loqueris?
#5
Posted 30 September 2010 - 10:12 PM
if we do not know what is the item in the external file,what should we do to calculate the total number of items?
#6
Posted 01 October 2010 - 05:35 AM
Read it as binary data and count new lines? Does this work?
A conclusion is where you got tired of thinking.
#define class struct // All is public.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









