Troubles simply reading a file

Discussion in 'C Programming' started by jacobi, Sep 7, 2009.

  1. jacobi

    jacobi

    Joined:
    Sep 7, 2009
    Messages:
    2
    I've tried reading a file several different ways. I get nothing every time. The code seems exactly right.

    Read a file >> print the text.
    Simple.
    I've written similar code.... what am I missing guys?

    (I have the text file in the solution dir, and the project dir - pretty sure i just need it in the project dir? but i wasn't sure - c++ AND VS n00b )

    I've also tried using a whole pathname to read the text file. I get nothing.

    Here's my brilliant code :barresed: :

    // stdafx.h : include file for standard system include files,
    // or project specific include files that are used frequently, but
    // are changed infrequently
    //

    #pragma once

    #include "targetver.h"

    #include <stdio.h>
    #include <tchar.h>

    #include <iostream>
    #include <fstream>
    #include <string>

    --------

    // test.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"

    using namespace std;


    int _tmain(int argc, _TCHAR* argv[])
    {
    ifstream in("test.txt");
    string s, line;
    while( getline(in, line) )
    s += line + "\n";
    cout << s;

    return 0;
    }

     
    Last edited: Sep 7, 2009
    jacobi, Sep 7, 2009
    #1
    1. Advertising

  2. jacobi

    umeshkvguptha

    Joined:
    Sep 7, 2009
    Messages:
    2
    Location:
    Pune,India
    code is correct...
    Could you try with giving complete path like

    ifstream in("c:\\Program Files\\Microsoft Visual Studio\\MyProjects\\soln\test.txt");
     
    umeshkvguptha, Sep 7, 2009
    #2
    1. Advertising

  3. jacobi

    jacobi

    Joined:
    Sep 7, 2009
    Messages:
    2

    Still nothing. I think it's somewhere in the getline();
     
    jacobi, Sep 7, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mohamed Naoufel Ben Salah

    java socket input reading troubles

    Mohamed Naoufel Ben Salah, Dec 11, 2003, in forum: Java
    Replies:
    2
    Views:
    2,642
    Steve Horsley
    Dec 12, 2003
  2. Arun
    Replies:
    0
    Views:
    443
  3. pbd22
    Replies:
    1
    Views:
    1,401
    pbd22
    Jan 8, 2007
  4. Dox Xer
    Replies:
    3
    Views:
    140
    Dox Xer
    Sep 11, 2010
  5. Jack
    Replies:
    2
    Views:
    215
    Dave Weaver
    Jan 7, 2008
Loading...

Share This Page