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;
}
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: