Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open file and print

Status
Not open for further replies.

Herbalizer

Programmer
Apr 30, 2005
2
US
/*
For some reason the following code does not print
the first line of the txt file. I'm pretty sure
the code is right, dont know if its my compiler
or what not. I'm using dev-c++. Any suggestions
are welcome.
*/

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
using namespace std;

int main () {
char read[100][50];

ifstream input;
input.open("c:\temp.txt");

input.getline(read[0], 50);

cout << endl << read[0] << endl;

system("PAUSE");
return 0;
}

 
So, i just installed Microsoft Visual C++ 6.0 Standard Edition. And im getting the same problem. Can someone with the same compiler tell me if it works for you?
 
Are you sure your text file doesn't start with a blank line?

Also, don't forget \ is the escape character in C++, so you should really have
Code:
input.open("c:\\temp.txt");

Please use the [tt][ignore]
Code:
[/ignore][/tt]
tags when posting code.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top