|
-
September 6th, 2009, 11:16 PM
#1
[RESOLVED] Simply reading txt file - oddly not working
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 :
// 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[])
{
string str;
ifstream in("test.txt", ios::in);
in.open("test.txt");
getline(in, str);
cout << str << endl;
in.close();
return 0;
}
jacobi
Last edited by jacobis; September 7th, 2009 at 10:27 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|