Reading in TXT file and Ignore Integer

Need to ignore interger in text file and read char into array.

Page 1 of 1

3 Replies - 985 Views - Last Post: 16 November 2008 - 05:23 PM Rate Topic: -----

#1 DevWalt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-May 08

Reading in TXT file and Ignore Integer

Post icon  Posted 16 November 2008 - 01:28 PM

	inputFile.open("StudentAnswers2.txt"); // Open File

	for(int j=0; j < size2; j++)
	{
		inputFile >> studentAnswer2[j];
		cout << studentAnswer2[j] << endl;
		
	}inputFile.close();
	cout << endl;

// The contents of the file start with an integer (1ABCDE and so on)
// 1 indicates the student and there are 11 students.  I want to ignore the integer
// Currently I am getting 1ABCD stored in the char array.



Is This A Good Question/Topic? 0
  • +

Replies To: Reading in TXT file and Ignore Integer

#2 DoubleFission  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 223
  • Joined: 20-September 08

Re: Reading in TXT file and Ignore Integer

Posted 16 November 2008 - 01:35 PM

	int junk;

	inputFile.open("StudentAnswers2.txt"); // Open File

	inputFile >> junk;

	for(int j=0; j < size2; j++)
	{
		inputFile >> studentAnswer2[j];
		cout << studentAnswer2[j] << endl;
		
	}inputFile.close();
	cout << endl;



That'll read the integer into the 'junk' piece of memory and the characters into the 'studentAnswer2' memory.

This post has been edited by DoubleFission: 16 November 2008 - 01:35 PM

Was This Post Helpful? 1
  • +
  • -

#3 DevWalt  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-May 08

Re: Reading in TXT file and Ignore Integer

Posted 16 November 2008 - 02:06 PM

View PostDoubleFission, on 16 Nov, 2008 - 12:35 PM, said:

	int junk;

	inputFile.open("StudentAnswers2.txt"); // Open File

	inputFile >> junk;

	for(int j=0; j < size2; j++)
	{
		inputFile >> studentAnswer2[j];
		cout << studentAnswer2[j] << endl;
		
	}inputFile.close();
	cout << endl;



That works fine for the first student can I loop this the filter 10 other students?

This post has been edited by DevWalt: 16 November 2008 - 02:10 PM

Was This Post Helpful? 0
  • +
  • -

#4 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 275
  • View blog
  • Posts: 1,764
  • Joined: 20-September 08

Re: Reading in TXT file and Ignore Integer

Posted 16 November 2008 - 05:23 PM

View PostDevWalt, on 16 Nov, 2008 - 01:06 PM, said:

...That works fine for the first student can I loop this the filter 10 other students?


Yes ... :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1