c++ GetUpperBound equivalent
-
i have the Following vb.net 2008 routine i am trying to get c++ to have the same functionality having alot of issues with c++ conversion, any help with this would be great...
Public Sub New()
Try
If ORIHoles Is Nothing Then
ReDim ORIHoles(49)
Dim ff As Integer = FreeFile()
Dim tempstr As String
Dim atempstr() As String
FileOpen(ff, "postable.csv", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
Do While Not EOF(ff)
tempstr = LineInput(ff)
atempstr = tempstr.Split(",")
If atempstr.GetUpperBound(0) = 2 Then
ORIHoles(CInt(atempstr(0))).Angle = CDbl(atempstr(1))
ORIHoles(CInt(atempstr(0))).Hypot = CDbl(atempstr(2))
End If
Loop
FileClose(ff)
End If
Catch ex As Exception
GeneralErrorHandler(ex.ToString)
End Try
End Sub -
i have the Following vb.net 2008 routine i am trying to get c++ to have the same functionality having alot of issues with c++ conversion, any help with this would be great...
Public Sub New()
Try
If ORIHoles Is Nothing Then
ReDim ORIHoles(49)
Dim ff As Integer = FreeFile()
Dim tempstr As String
Dim atempstr() As String
FileOpen(ff, "postable.csv", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
Do While Not EOF(ff)
tempstr = LineInput(ff)
atempstr = tempstr.Split(",")
If atempstr.GetUpperBound(0) = 2 Then
ORIHoles(CInt(atempstr(0))).Angle = CDbl(atempstr(1))
ORIHoles(CInt(atempstr(0))).Hypot = CDbl(atempstr(2))
End If
Loop
FileClose(ff)
End If
Catch ex As Exception
GeneralErrorHandler(ex.ToString)
End Try
End Sub -
i have the Following vb.net 2008 routine i am trying to get c++ to have the same functionality having alot of issues with c++ conversion, any help with this would be great...
Public Sub New()
Try
If ORIHoles Is Nothing Then
ReDim ORIHoles(49)
Dim ff As Integer = FreeFile()
Dim tempstr As String
Dim atempstr() As String
FileOpen(ff, "postable.csv", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
Do While Not EOF(ff)
tempstr = LineInput(ff)
atempstr = tempstr.Split(",")
If atempstr.GetUpperBound(0) = 2 Then
ORIHoles(CInt(atempstr(0))).Angle = CDbl(atempstr(1))
ORIHoles(CInt(atempstr(0))).Hypot = CDbl(atempstr(2))
End If
Loop
FileClose(ff)
End If
Catch ex As Exception
GeneralErrorHandler(ex.ToString)
End Try
End Sub -
ccodebase wrote:
having alot of issues with c++ conversion
Unless you tell us what thos issues are we cannot help you correct them. And please post your questions once only.
ok well, the issue is i need exact functionality in C++ with a class or function that performs as the vb.net code does, i do have this that i am hard coding all the Values into, CSV Structure is 01,-0.12343,1.34532 02,-0.62343,1.74532 03,-0.22343,1.34532 04,-0.62343,1.74532
using namespace std;
int main()
{
// initialize container map mp; // insert elements mp.insert({ -0.12343, 1.34532}); /// used as example
mp.insert({ 0.22343, 1.74532});
mp.insert({ -0.12343, 1.34532});
mp.insert({ -0.12343, 1.34532});
// when 11 is present auto it = mp.upper\_bound(11); cout << "The upper bound of key 11 is "; cout << (\*it).first << " " << (\*it).second << endl; // when 13 is not present it = mp.upper\_bound(13); cout << "The upper bound of key 13 is "; cout << (\*it).first << " " << (\*it).second << endl; // when 17 is exceeds the maximum key, so size // of mp is returned as key and value as 0. it = mp.upper\_bound(17); cout << "The upper bound of key 17 is "; cout << (\*it).first << " " << (\*it).second; return 0;
}
9:23
The upper bound of key 11 is 12 30
The upper bound of key 13 is 14 40
The upper bound of key 17 is 4 0 -
ok well, the issue is i need exact functionality in C++ with a class or function that performs as the vb.net code does, i do have this that i am hard coding all the Values into, CSV Structure is 01,-0.12343,1.34532 02,-0.62343,1.74532 03,-0.22343,1.34532 04,-0.62343,1.74532
using namespace std;
int main()
{
// initialize container map mp; // insert elements mp.insert({ -0.12343, 1.34532}); /// used as example
mp.insert({ 0.22343, 1.74532});
mp.insert({ -0.12343, 1.34532});
mp.insert({ -0.12343, 1.34532});
// when 11 is present auto it = mp.upper\_bound(11); cout << "The upper bound of key 11 is "; cout << (\*it).first << " " << (\*it).second << endl; // when 13 is not present it = mp.upper\_bound(13); cout << "The upper bound of key 13 is "; cout << (\*it).first << " " << (\*it).second << endl; // when 17 is exceeds the maximum key, so size // of mp is returned as key and value as 0. it = mp.upper\_bound(17); cout << "The upper bound of key 17 is "; cout << (\*it).first << " " << (\*it).second; return 0;
}
9:23
The upper bound of key 11 is 12 30
The upper bound of key 13 is 14 40
The upper bound of key 17 is 4 0 -
ok well, the issue is i need exact functionality in C++ with a class or function that performs as the vb.net code does, i do have this that i am hard coding all the Values into, CSV Structure is 01,-0.12343,1.34532 02,-0.62343,1.74532 03,-0.22343,1.34532 04,-0.62343,1.74532
using namespace std;
int main()
{
// initialize container map mp; // insert elements mp.insert({ -0.12343, 1.34532}); /// used as example
mp.insert({ 0.22343, 1.74532});
mp.insert({ -0.12343, 1.34532});
mp.insert({ -0.12343, 1.34532});
// when 11 is present auto it = mp.upper\_bound(11); cout << "The upper bound of key 11 is "; cout << (\*it).first << " " << (\*it).second << endl; // when 13 is not present it = mp.upper\_bound(13); cout << "The upper bound of key 13 is "; cout << (\*it).first << " " << (\*it).second << endl; // when 17 is exceeds the maximum key, so size // of mp is returned as key and value as 0. it = mp.upper\_bound(17); cout << "The upper bound of key 17 is "; cout << (\*it).first << " " << (\*it).second; return 0;
}
9:23
The upper bound of key 11 is 12 30
The upper bound of key 13 is 14 40
The upper bound of key 17 is 4 0 -
Try this:
map mp;
mp.insert({5,7}); /// used as example
mp.insert({7,33});
mp.insert({11,1});
mp.insert({16,5});
auto it = mp.upper_bound(11);
cout << "The upper bound of key 11 is ";
cout << it->first << " " << it->second << endl;this is a vision cart reader as the carts are read it has a certain pattern in the grid so what the initial goal was to provide an equivalent Class or function to the vb.net snippet earlier in the post it reads a CSV file that has 48 Values pertaining to locations on a 7 x 7 Grid 7^2
Org CSV Structure is
01,-0.12343,1.34532
02,-0.62343,1.74532
03,-0.22343,1.34532
04,-0.62343,1.74532
..
through 48when the camera system see's the holes through the Cart by light it knows what number it is
-
Sorry I don't understand. You declare a
map
and then try to store double values into it. And what are 11, 13 and 17 supposed to relate to? -
Try this:
map mp;
mp.insert({5,7}); /// used as example
mp.insert({7,33});
mp.insert({11,1});
mp.insert({16,5});
auto it = mp.upper_bound(11);
cout << "The upper bound of key 11 is ";
cout << it->first << " " << it->second << endl;