473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

end of Line peeking

if(data.peek()=="\n")

I'm trying to use an if statement to break out of a for loop while looking for a end of line statement and that's the code I'm using now but I keep getting compiler error about comparison between a pointer and an integer

FYI: data is an outside text document
so any help would be appreciated
Sep 16 '06 #1
5 7849
zeny
44
You cant compare two strings using the '==' operator. To compare two strings you must use the function strcmp(string), from the string library. So, in your case it would be: if((data.peek()).strcmp("\n")).

Regards
Sep 16 '06 #2
71 C:\Dev-Cpp\Lab 1.cpp `strcmp' is not a type

is the error message I got when I tryed implement your coding
Sep 16 '06 #3
for(int sub=0;sub<20;sub++)
{
cout << studentNames[sub];
if((data.peek()).strcmp("\n"))
break;
else
char test=data.get();
if(test==correctAns[sub])
{
cout << "true\n";
}
else
{
cout << "false\n";
}
}

this is the entire for loop I'm using if that helps any
Sep 16 '06 #4
zeny
44
I´m sorry for induce you in error about the strcmp function. Try the following instead:

if(strcmp(data.peek(), "\n") == 0)
Sep 16 '06 #5
Banfa
9,065 Expert Mod 8TB
if(data.peek()=="\n")

I'm trying to use an if statement to break out of a for loop while looking for a end of line statement and that's the code I'm using now but I keep getting compiler error about comparison between a pointer and an integer

FYI: data is an outside text document
so any help would be appreciated
The problem is that data.peek() returns an integer type (and int probably) which is the character peeked. However "\n" is a string and therefore of type char *. You need to use a character constant instead of a string constant,

if(data.peek()=='\n')

Note single quotes instead of double quotes.

If future when asking questions it is important to give all the information. Even in you code listing you have not given the type of data which makes it hard to know if the information I have looked up about peek is true. I have assumed that data is a derivertive of basic_stream.
Sep 17 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: les_ander | last post by:
Hi, suppose I am reading lines from a file or stdin. I want to just "peek" in to the next line, and if it starts with a special character I want to break out of a for loop, other wise I want to...
7
by: jamait | last post by:
Hi all, I m trying to read in a text file into a datatable... Not sure on how to split up the information though, regex or substrings...? sample: Col1 Col2 ...
6
by: mary | last post by:
When we use string line; while (getline(in,line)) { out.write(line.c_str(),line.size()); out.put('\n'); } in.close();
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
3
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. ...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
6
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
11
by: xdevel | last post by:
Hi, I don't understand option. if I write: #line 100 "file" I change file numeration to start to line 100 but what "file" ? any example?
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.