Can't Read a File

Split from unrelated topic

Page 1 of 1

2 Replies - 204 Views - Last Post: 04 December 2012 - 11:01 AM Rate Topic: -----

#1 pradeep rawat  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 2
  • Joined: 03-December 12

Can't Read a File

Posted 04 December 2012 - 06:08 AM

i have a file in which only numbers are der like
23
34
45
i m reading it and adding but its not happening
these are my codes
#include <iostream>
#include <fstream>
using namespace std;

int main()
{

int sum=0;
ifstream in("outfile.txt" );

  if(!in) {
    cout << "Cannot open input file.\n";
    return 1;
  }

 if (in)
{

  for(int i = 0; i < 2 ; i++)
sum = sum + ch;
 cout << sum  << " \n";
  in.close();

  return 0;
}}


This post has been edited by no2pencil: 04 December 2012 - 07:15 AM
Reason for edit:: Added Code Tags


Is This A Good Question/Topic? -1
  • +

Replies To: Can't Read a File

#2 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: Can't Read a File

Posted 04 December 2012 - 06:30 AM

Where did ch come from? sum = sum + ch;

Quote

i m reading it and adding but its not happening

Because you have opened a file and you are not reading from it... You need to use the in object you have created to read from the file...

Here is a tutorial about file I/O... Read it!
Was This Post Helpful? 1
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,519
  • Joined: 23-August 08

Re: Can't Read a File

Posted 04 December 2012 - 11:01 AM

How the hell is this related to your original post?

SMFH

Split into new topic.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1