Troubles simply reading a file

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

  1. jacobi

    jacobi

    Joined:
    Sep 7, 2009
    Messages:
    2
    Likes Received:
    0
    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. Advertisements

  2. jacobi

    umeshkvguptha

    Joined:
    Sep 7, 2009
    Messages:
    2
    Likes Received:
    0
    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. Advertisements

  3. jacobi

    jacobi

    Joined:
    Sep 7, 2009
    Messages:
    2
    Likes Received:
    0

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

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. frank
    Replies:
    0
    Views:
    572
    frank
    Jul 11, 2003
  2. michael
    Replies:
    2
    Views:
    338
    =?Utf-8?B?RGF2aWQgQ29lLCBNQ1A=?=
    Feb 23, 2004
  3. coollzh
    Replies:
    0
    Views:
    414
    coollzh
    May 18, 2004
  4. Mohamed Naoufel Ben Salah

    java socket input reading troubles

    Mohamed Naoufel Ben Salah, Dec 11, 2003, in forum: Java
    Replies:
    2
    Views:
    2,829
    Steve Horsley
    Dec 12, 2003
  5. Arun
    Replies:
    0
    Views:
    511
  6. pbd22
    Replies:
    1
    Views:
    1,619
    pbd22
    Jan 8, 2007
  7. Dox Xer
    Replies:
    3
    Views:
    208
    Dox Xer
    Sep 11, 2010
  8. Jack
    Replies:
    2
    Views:
    341
    Dave Weaver
    Jan 7, 2008
Loading...