Troubles simply reading a file

Joined
Sep 7, 2009
Messages
2
Reaction score
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:
Joined
Sep 7, 2009
Messages
2
Reaction score
0
code is correct...
Could you try with giving complete path like

ifstream in("c:\\Program Files\\Microsoft Visual Studio\\MyProjects\\soln\test.txt");
 
Joined
Sep 7, 2009
Messages
2
Reaction score
0
umeshkvguptha said:
code is correct...
Could you try with giving complete path like

ifstream in("c:\\Program Files\\Microsoft Visual Studio\\MyProjects\\soln\test.txt");


Still nothing. I think it's somewhere in the getline();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top