Trying to create a program which reads and echos the contents of an input data file, which consists of two records. When I complile my code I keep getting a "error C2001: newline in constant" error. Read every forum regarding the "error C2001: newline in constant" error but I am still not clear as to where my code is erroring out. Can anyone help point me in the right direction?
Thanks
My code: - //************************************************************************************************
-
// Test Program: Chapter 6 A noninteractive program which reads and echos input data file.
-
//
-
//
-
//************************************************************************************************
-
#include<iostream.h>
-
#include<iomanip>
-
#include<fstream> //For input data file.
-
using namespace std;
-
-
-
int main()
-
{
-
float side; // 1st input data field on each record: must be >=0
-
float area; // 2nd input data filed on each record: must be >=0
-
ifstream inFile; // Data file: each record shows side
-
-
-
//Attempt to open the input data file
-
inFile.open("sidearea.dat");
-
if(!inFile) // If file can't be found (we're in a fail state):
-
{
-
cout<<("Unable to open input file, program abnormally ended\n");
-
return 1; // Terminate program early, with return code=1:
-
}
-
-
//Get first pair of input data values for side and area, then echo print:
-
inFile>>side>>area;
-
cout<<"Record1:Side is"<<side<<"and area is"<<area<<endl;
-
-
//Check 1st record for I/O errors, then for valid data values:
-
;if(!inFile)
-
{
-
cout<<"I/O Error on input file, program abnormanlly ended\n";
-
return 1;
-
}
-
else
-
{
-
if(side<0)
-
cout<<"Warning side is invalid, must be = or > 0"<<endl;
-
if(area=(side*side))
-
cout<<"Warning area is invalid, must not be = to side square"<<endl;
-
}
-
-
//Get second pair of input data values for side and area
-
inFile>>side>>area;
-
cout<<"Record2:Side is:<<side<<and area is<<area<<endl;
-
-
//Check 2nd record for I/O errors, then for valid data values:
-
;if(inFile)
-
{
-
cout<<("I/O Error on input file, program abnormally ended");
-
return 1;
-
}
-
else
-
{
-
if(side<0)
-
cout<<"Warning side is invalid, must be = or > 0"<<endl;
-
if(area=(side*side))
-
cout<<"I/O Error on input file, program abnormally ended"<<endl;
-
}
-
-
//Terminate program normally:
-
cout<<"No I/O Errors in input file, pgm. terminated normally"<<endl;
-
return 0;
-
}
3 15417
Trying to create a program which reads and echos the contents of an input data file, which consists of two records. When I complile my code I keep getting a "error C2001: newline in constant" error. Read every forum regarding the "error C2001: newline in constant" error but I am still not clear as to where my code is erroring out. Can anyone help point me in the right direction?
Thanks
My code:
/************************************************** **********************************************
// Test Program: Chapter 6 A noninteractive program which reads and echos input data file.
//
//
//************************************************** **********************************************
#include<iostream.h>
#include<iomanip>
#include<fstream> //For input data file.
using namespace std;
int main()
{
float side; // 1st input data field on each record: must be >=0
float area; // 2nd input data filed on each record: must be >=0
ifstream inFile; // Data file: each record shows side
//Attempt to open the input data file
inFile.open("sidearea.dat");
if(!inFile) // If file can't be found (we're in a fail state):
{
cout<<("Unable to open input file, program abnormally ended\n");
return 1; // Terminate program early, with return code=1:
}
//Get first pair of input data values for side and area, then echo print:
inFile>>side>>area;
cout<<"Record1:Side is"<<side<<"and area is"<<area<<endl;
//Check 1st record for I/O errors, then for valid data values:
;if(!inFile)
{
cout<<"I/O Error on input file, program abnormanlly ended\n";
return 1;
}
else
{
if(side<0)
cout<<"Warning side is invalid, must be = or > 0"<<endl;
if(area=(side*side))
cout<<"Warning area is invalid, must not be = to side square"<<endl;
}
//Get second pair of input data values for side and area
inFile>>side>>area;
cout<<"Record2:Side is:<<side<<and area is<<area<<endl;
//Check 2nd record for I/O errors, then for valid data values:
;if(inFile)
{
cout<<("I/O Error on input file, program abnormally ended");
return 1;
}
else
{
if(side<0)
cout<<"Warning side is invalid, must be = or > 0"<<endl;
if(area=(side*side))
cout<<"I/O Error on input file, program abnormally ended"<<endl;
}
//Terminate program normally:
cout<<"No I/O Errors in input file, pgm. terminated normally"<<endl;
return 0;
}
If this was copied directly, I would check this line:
//Check 1st record for I/O errors, then for valid data values:
;if(!inFile)
the 'if' statement has a ';' in front of it - that shouldn't be there.
Banfa 9,065
Expert Mod 8TB
What sicarie says is a minor error that is probably not stopping program compilation.
The "New line in constant" error is nearly always the result of failing to put the terminating " on a string constant.
In our case it happens on the cout line -
//Get second pair of input data values for side and area
-
inFile>>side>>area;
-
cout<<"Record2:Side is:<<side<<and area is<<area<<endl;
-
where you appear to have missed out several "
What sicarie says is a minor error that is probably not stopping program compilation.
The "New line in constant" error is nearly always the result of failing to put the terminating " on a string constant.
In our case it happens on the cout line -
//Get second pair of input data values for side and area
-
inFile>>side>>area;
-
cout<<"Record2:Side is:<<side<<and area is<<area<<endl;
-
where you appear to have missed out several "
Oh dang. I was thinking that couldn't just be it, but I missed that several times. Thanks, Banfa!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Charles Erwin |
last post by:
Is there any way, upon scanning in a file line by line to avoid
missing the last line if there is not a newline character (aka you
have to hit return on the last line of input in your file). I was...
|
by: TTroy |
last post by:
Hello,
I have found some peculiar behaviour in the fgets runtime library
function for my compiler/OS/platform (Dev C++/XP/P4) - making a C
console program (which runs in a CMD.exe shell).
The...
|
by: Jacob Bensabat |
last post by:
Hi
I am trying to do the following
template <class X>
class CA
{
public:
X m_a;
X m_b;
X Get(X& a,X& b)
|
by: Leo R |
last post by:
Hi all,
If an error occurs in an aspx-page, you can configure the web.config in a
way that the user automatically navigates to a certain page (e.g.
error.aspx).
My question: is it possible to...
|
by: Gerard |
last post by:
Hello
I have created a windows service to monitor a database, it starts some
checks when a timer elapses. The checks send emails depending on their
findings. My issue is that when I created a...
|
by: albert_reade |
last post by:
Could someone help me figure out why this error keeps occuring thanks
for the help.
error:
cc FordFulkerson.c
FordFulkerson.c:117:2: warning: no newline at end of file
Code:
#include...
|
by: pbd22 |
last post by:
hi.
i keep getting this error.
as i understand it, my xml isn't formatted correctly.
the online errata suggests the standard formatting
to solve this problem:
element
(tab) (tab) element
|
by: rossum |
last post by:
I want to declare a const multi-line string inside a method, and I am
having some problems using Environment.NewLine.
I started out with:
class foo {
public void PrintStuff() {
const...
|
by: Sajeena |
last post by:
I have used smtp mail scripts
<?php
function authgMail($from, $namefrom, $to, $nameto, $subject, $message) {
$smtpServer = "192.168.xxx.xxx"; //ip address of the mail server. This can also be...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |