Question Locked

How to read and display strings in C ?

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

so i have a txt file and the first line is "Rain Fall Average"

what code can i use to read the first line and then display it on the console window.

this is what i have so far.

#include
#include
using namespace std;
int main()
{

ifstream inputFile;
char study_name[71]; //NOTE - study name must contain up to 70 character//

inputFile.open("c:\\rainfall.txt");
cout << "Reading data from file" << endl;
inputFile >> study_name; //Problem here - It only displays "Rain"//
cout << study_name << endl;

inputFile.close();

//is it possible displaying the title with a char variable or must i use a string //

2 replies

by tony hopkinson

reads up to first white space, commas etc..

inputFile.GetLine() is what you need

This discussion is closed to new replies.