Home > Back-end >  C simple questions
C simple questions

Time:09-20

In the Parse.
in the h
# # ifndef PARSE_H_
# define PARSE_H_
#include
#include
The class Parse
{
STD: : string s.
Public:
Parse (STD: : string s_) : s {s_} {};
Int getFirst ();
Int getLast ();
};

# endif


in the CPP in the Parse.# include "Parse. H"

Int Parse: : getFirst ()
{
Int m1=0;
Int m2=0;
for (int i=0; i <=s.s considering () - 1; I++)
{
If (s [I] & gt;='0' & amp; & S [I] <='9')
{
M1=I;
break;
}
}
M2 equals m1;
While (s/m2 & gt;='0' & amp; & S [m2] <='9')
{
M2 + +;
}
STD: : string s1=s.s ubstr (m1, m2 - m1);
Int n=STD: : stol (s1);
return n;
}

Int Parse: : getLast ()
{
Int m3=0;
Int the m4=0;
For (size_t I=s.s considering () - 1; I & gt; 0; I -)
{
If (s [I] & gt;='0' & amp; & S [I] <='9')
{
M3=I;
break;
}
}
The m4=m3;
While (s/m4 & gt;='0' & amp; & S/m4 & lt;='9')
{
The m4 -;
}
STD: : string s4=s.s ubstr (m4, m3);
Int n=STD: : stol (s4);
return n;
}

In the main.
in the CPP
# include "Parse. H"
#include
#include
Using STD: : cin;
Using STD: : cout;
Using STD: : endl;
Using STD: : string;

Int main ()
{
String s {};
Cin & gt;> s;
The Parse p {s};
Int c=p.g etFirst ();
Int d=p.g etLast ();
Cout & lt; Cout & lt;
return 0;
}

In vscode when compile operation to C: \ Users \ zs \ AppData \ Local \ Temp \ ccwaNqWu o: main. CPP: (. The text + 0 x115) : undefined reference to ` Parse: : getFirst ()
'C: \ Users \ zs \ AppData \ Local \ Temp \ ccwaNqWu o: main. CPP: (. The text + 0 x124) : undefined reference to ` Parse: : getLast ()
'Collect2. Exe: error: ld returned 1 exit status of such errors,
In vs when compile operation to abort () has had called where is my wrong

CodePudding user response:

V should be debugged, string s wrong, don't add {}

CodePudding user response:

No compilation connection parse. CPP

CodePudding user response:

The
reference 1/f, Simple, Soft reply:
vs debugged, should be an error in the string s, don't add {}
it may not seem like the wrong here

CodePudding user response:

refer to the second floor met the goddess response:
no connection parse. CPP
that how to do, is in the main CPP added a # include "parse. CPP"

CodePudding user response:

My experiment can compile, there should be no compile connection parse. The CPP, you can delete the parse. CPP to build a try,

CodePudding user response:

reference 5 floor weixin_41556000 reply:
I experiment can compile, there should be no compile connection parse, CPP, you can delete the parse. The CPP to build a try,
I have deleted all to build as if still won't do, don't know what happened, ah

CodePudding user response:

No edit link the Parse. CPP, json file in your task. Add
 "${fileDirname} \ \ Parse CPP",//similar to add the necessary files, multiple file can be compiled, also can use a makefile 

As shown in figure

You can compile the success,
  • Related