473,657 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help in STRING compare ?

Please help, I am not sure why this code not even compile due to
line 39 and 44.
Thanks in advance for any help
1 #include <cctype>
2 #include <iostream>
3 #include <string>
4 #include <vector>
5
6 using std::cin;
7 using std::cout;
8 using std::endl;
9 using std::getline;
10 using std::string;
11 using std::vector;
12
13 double split (const std::string&,in t);
14
15 int main()
16 {
17 string s =("1.1,2.3,3.5, 4.2");
18
19 const int loc = 3;
20 double results;
21
22 results= split(s,loc);
23 cout <<"RESULT IS"<<" "<< results<<endl;
24
25
26 return 0;
27 }
28
29
30 double split(const string& fw_answer,const int ok )
31 {
32 double data;
33 vector<string> ret;
34 const string separator (",");
35 typedef string::size_ty pe string_size;
36 string_size i = 0;
37
38 while (i != fw_answer.size( )) {
39 while (i != fw_answer.size( ) && (fw_answer[i]==separator))
40 ++i;
41
42 string_size j = i;
43
44 while (j != fw_answer.size( ) && !(fw_answer[j]==separator))
45 ++j;
46
47 if (i != j) {
48 ret.push_back(f w_answer.substr (i, j - i));
49 i = j;
50 }
51
52 }
53 for (vector<string> ::size_type i = 0; i != ret.size(); ++i)
54 if (i==ok){
55 data = atof(ret[i].c_str());
56 cout <<"HERE it is" <<" "<< ret[i] << endl;
57 }
58 return data;
59 }
60

Nov 7 '05 #1
3 2307
tv****@hotmail. com wrote:
Please help, I am not sure why this code not even compile due to
line 39 and 44.
Thanks in advance for any help
1 #include <cctype>
2 #include <iostream>
3 #include <string>
4 #include <vector>
5
6 using std::cin;
7 using std::cout;
8 using std::endl;
9 using std::getline;
10 using std::string;
11 using std::vector;
12
13 double split (const std::string&,in t);
14
15 int main()
16 {
17 string s =("1.1,2.3,3.5, 4.2");
18
19 const int loc = 3;
20 double results;
21
22 results= split(s,loc);
23 cout <<"RESULT IS"<<" "<< results<<endl;
24
25
26 return 0;
27 }
28
29
30 double split(const string& fw_answer,const int ok )
31 {
32 double data;
33 vector<string> ret;
34 const string separator (",");
Try:
char const separator = ',';

35 typedef string::size_ty pe string_size;
36 string_size i = 0;
37
38 while (i != fw_answer.size( )) {
39 while (i != fw_answer.size( ) && (fw_answer[i]==separator))
40 ++i;
41
42 string_size j = i;
43
44 while (j != fw_answer.size( ) && !(fw_answer[j]==separator))
45 ++j;
46
47 if (i != j) {
48 ret.push_back(f w_answer.substr (i, j - i));
49 i = j;
50 }
51
52 }
53 for (vector<string> ::size_type i = 0; i != ret.size(); ++i)
54 if (i==ok){
55 data = atof(ret[i].c_str());
56 cout <<"HERE it is" <<" "<< ret[i] << endl;
57 }
58 return data;
59 }
60

Best

Kai-Uwe Bux
Nov 7 '05 #2
On Mon, 07 Nov 2005 11:37:51 -0800, tvn007 wrote:
Please help, I am not sure why this code not even compile due to
line 39 and 44.
Thanks in advance for any help
1 #include <cctype>
Consider, for all your posts after this one, dropping the line numbers and
simply commenting the lines you're talking about, like this;

if (blahbla) { // line # 42
2 #include <iostream>
3 #include <string>
4 #include <vector>
5
6 using std::cin;
7 using std::cout;
8 using std::endl;
9 using std::getline;
10 using std::string;
11 using std::vector;
12
13 double split (const std::string&,in t);
14
15 int main()
16 {
17 string s =("1.1,2.3,3.5, 4.2");
18
19 const int loc = 3;
20 double results;
21
22 results= split(s,loc);
23 cout <<"RESULT IS"<<" "<< results<<endl;
24
25
26 return 0;
27 }
28
29
30 double split(const string& fw_answer,const int ok )
31 {
32 double data;
33 vector<string> ret;
34 const string separator (",");
Why not simply
const char separator(',');

???
35 typedef string::size_ty pe string_size;
36 string_size i = 0;
37
38 while (i != fw_answer.size( )) {
39 while (i != fw_answer.size( ) && (fw_answer[i]==separator))
You're trying to compare a char (fw_answer[i]) to a string (separator).
As soon as you make 'separator' a plain 'char', your problem will be
solved.
40 ++i;
41
42 string_size j = i;
43
44 while (j != fw_answer.size( ) && !(fw_answer[j]==separator))
Same problem
45 ++j;
46
47 if (i != j) {
48 ret.push_back(f w_answer.substr (i, j - i));
49 i = j;
50 }
51
52 }
53 for (vector<string> ::size_type i = 0; i != ret.size(); ++i)
54 if (i==ok){
55 data = atof(ret[i].c_str());
56 cout <<"HERE it is" <<" "<< ret[i] << endl;
57 }
58 return data;
59 }
60


V
Nov 7 '05 #3
Thanks all for the help !

Nov 7 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
6207
by: webzila | last post by:
Hello, I have to write a program for an 8051 micro-controller using micro-C to monitor Switch 1 and if the switch in pushed the message "switch 1 pushed" should be displayed in the LCD. Also the microcontroller should display in the LCD the value of the voltage applied to the input of the ADC. The above procedure should only execute once the user has entered "1234" using a keypad that is attached to the 8051 microprocessor.
8
3253
by: Jack Addington | last post by:
I want to scroll through the alphabet in order to scroll some data to the closest name that starts with a letter. If the user hits the H button then it should scroll to the letter closest to H. If no one exists with H, then go to I, etc. If its near the end, say 'V', and the last person is a 'T' then it should work its way back up the alphabet. I was trying to loop as if the Char's were ints but I am having problems I have buttons...
7
2652
by: Drew Berkemeyer | last post by:
I've encounted a pretty strange problem and I'm not quite sure what to make of it. I have a web service that consumes an XML file as well as a few other parameters. This web service works fine if I use the web test interface. It also works fine if I call it from an ASP.NET page that has a text box where the XML is pasted and then passed on. However, I get an exception if I use an <input type="file"> control on the ASP page that allows...
3
1213
by: Craig | last post by:
Hi I'm having some troubles getting my regex to work. I have a string as follows The "quick and brown" fox "jumped over the" lazy dog. The output should be as follows: The "quick and brown" fox "jumped and over and the" lazy dog. So the expression needs to insert 'and' between the groups of words enclosed in double quotes, ignoring the insert if the 'and' word exists bewteen the
5
3780
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public List<RoleData> GetRoles() { return GetRoles(null, false); }
6
1873
by: Burt | last post by:
I need to create a collection of classes (or structures) can be accessed by a string key, eg MyColl("ShortName5").Name for class with key ShortName5. But it also has to be sorted by a second ordering field. Hashtable offers access by key, but is not sorted. Arraylist is sorted (the fields will come presorted from the db), but I can't access by key. SortedList can't be sorted by a field different from the key field.
4
1628
nomad
by: nomad | last post by:
I'm very new to java and programing. I need some help with this. Check each user entry to ensure validity. Color is either Black, White, or Red. if the user enter the wrong color the following with show ERROR – Incorrect color – try again: I'm tring to figure out if this is a while loop or a do while loop. and help would be great. Here is what I have so far. //make a Scanner object for color
7
1077
by: cirfu | last post by:
pat = re.compile("(\w* *)*") this matches all sentences. if fed the string "are you crazy? i am" it will return "are you crazy". i want to find a in a big string a sentence containing Zlatan Ibrahimovic and some other text. ie return the first sentence containing the name Zlatan Ibrahimovic.
0
1456
by: =?Utf-8?B?Sm9obkJhdGVz?= | last post by:
This is my first custom installer and essentially I needed to create one that installed windows installer 3.1 then installed .Net 2.0 Service Pack 1. I could not find a pre-packaged .Net 2.o SP 1 installer package anywhere so this is my attempt. The problem seems to be that when I first created it if .NET 2.0 was installed it would not install .NET 2.0 SP1 so I commented out the line where it checks but that leads the installer to try...
11
4354
by: blunt | last post by:
trying to write a program to write the configuration files for a load of wireless access points. i've never been a good programmer and haven't done any for nearly a decade so have obviously made some mistakes, i'm using cygwin on a windows pc and it seems that some functions cause stack overflows so am using fgets instead of fgetc (don't know y it solved the problem but that part is working). my problem now is that i am reading strings a few...
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.