|
|
std::getline() isn't part of C stdio, its part of C++. The getline with the signature int getline(char **, size_t *, FILE *) (i.e C stdio, thus the FILE * parameter) is not provided by MS in the windows C/C++ environment. Or at least it wasn't with VS 2017. It might have been added since then, but I don't think so.
Keep Calm and Carry On
|
|
|
|
|
I have tried:
std::ifstream ifs("curl --header \"x-api-key:ABCD\" -s https://api.test.se/api/mydata");
while (ifs.good())
{
std::string line;
while (std::getline(ifs, line))
{
std::cout << line.c_str() << std::endl;
}
}
Nothing retrieved.
|
|
|
|
|
std::ifstream reads files, and does not have a constructor which executes an external program. You should go back to pure C and use the _popen function.
[edit]
This all you need:
char buffer[132];
FILE* pipette = _popen("curl --header \"x-api-key:ABCD\" -s https://api.test.se/api/mydata", "r");
while (fgets(buffer, 132, pipette))
{
printf("%s", buffer);
}
[/edit]
modified 4-Jul-22 15:32pm.
|
|
|
|
|
Yes, that seems to work. Thank you all of you !
|
|
|
|
|
Of course not, unless you actually have a file in your current directory called curl --header "x-api-key:ABCD" -s https://api.test.se/api/mydata.
Keep Calm and Carry On
|
|
|
|
|
I tried to do a basic calculation for testing the performance of different programming languages:
C/C++: (***3.05 s***)
int main()
{
int start = clock();
double result;
for (size_t i = 1; i < 100000000; i++)
{
result = sin((i * 25) / i * i);
}
int end = clock();
std::cout << "it took " << end - start << "ticks std::endl;
}
C#: (***2.452 s***)
using System.Diagnostics;
class TestClass
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
double result;
sw.Start();
{
for (int i = 1; i < 100000000; i++)
{
result = Math.Sin((i * 25)/i * i);
}
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds.ToString());
}
}
And the same calculation in Python took 22.14 s to complete
Why is C# faster than C++?
|
|
|
|
|
I'd expect all "intermediate" calculations in C# to be performed as "int", since you have not supplied a single float or double on the right of the equation.
And you neglected to display / verify "result".
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Note that Math.Sin is implemented in native code, see the Reference Source (not for the implementation, but for the fact that there's no implementation there). So this isn't really a benchmark of C# vs C++, but one sine written in C++ vs another sine written in C++.
|
|
|
|
|
Both of the previous answers are correct.
On my machine, with VS2019, this code
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
double result=0.0;
sw.Start();
{
for (int i = 1; i < 100000000; i++)
{
result += Math.Sin((i * 25.0) / i * i);
}
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds.ToString());
Console.WriteLine(string.Format("{0}",result));
} produces
4739
-7,98150964297362
While the following
int main()
{
int start = clock();
double result = 0.0;
for (size_t i = 1; i < 100000000; i++)
{
result += sin((i * 25.0) / i * i);
}
int end = clock(); std::cout << (1000.0 * (end - start) / CLOCKS_PER_SEC) << "\n";
std::cout << result << "\n";
} outputs
4153
-7.98151
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
how to create
image background datagrid
|
|
|
|
|
|
Anything not in the foreground, is considered as being in the background.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
could you guys recommend me a file IO library. I need not just the library itself but also some explanations to it, like an article.
|
|
|
|
|
Not sure what you're looking for. C and C++ have file I/O.
For C++, start here[^]. Directory-level stuff was added in C++17 as <filesystem>[^].
For C, look here[^].
|
|
|
|
|
thanks Greg, I find that useful feedback
|
|
|
|
|
Is there something wrong with standard libraries ifstream/ofstream? If that's not to your liking, for some reason, maybe boost io or iostreams?
Without a bit more context, it's not clear what you're looking for.
Keep Calm and Carry On
|
|
|
|
|
|
|
|
Ask Away!. But maybe before you do, take a look at some of the threads posted here, and some of the questions and replies in the Quick Answers section. We don't do you work for you, but we're willing to help you with issues you may have. So questions like "why does this program produce unexpected results", or "why doesn't this compile" are likely to get answers. So are questions like "I'm trying to do X. Should I use a vector or a list?." But questions that ask "Implement a linked list, insert some values, sort and print the list", with no indication that you've made any attempt to solve the question yourself are likely to be either ignored or get a "We don't do homework" type of reply.
Keep Calm and Carry On
|
|
|
|
|
Well, aside from asking this exact question again (ok, you might ask it again to assert that VN and/or K5 is/are NOT robots I guess), use keywords in your PROGRAM by typing them into the "search" here at CP. The Discussions are titled and the QA is tagged. So keep those two things in mind also.
And.
Have a great day!
|
|
|
|
|
c ++ who can show me the direction of this article. There is an undirected star graph consisting of nodes labeled 1 to n. A star graph is a graph in which there is a central node and exactly n - 1 edges connecting the central node to every other node.
You are given a 2Dedges integer array where each edge edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Returns the center of the given star graph.
Input: edges =
4
1,2
5,1
1,3
1,4
Output: 1
|
|
|
|
|
And...
What's the problem?
Count the connections of each node.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
#include <iostream>
using namespace std;
bool checkSquareNumber(int num)
{
int i=0;
while(i*i <= num)
{
if(i*i==num)
return true;
i++;
}
return false;
}
int squareNumber(int num)
{
int i=0;
while(i*i <= num)
{
if(i*i==num)
return i;
i++;
}
return i;
}
int numberOfStep(int num)
{
int cnt =0;
int i =0;
while(num)
{
if(checkSquareNumber(num)== true)
{
num = squareNumber(num);
cnt++;
}
else if(num%3==0)
{
num = num/3;
cnt++;
}
else if(num%2==0)
{
num/=2;
cnt++;
}
else
{
num--;
cnt++;
}
}
return cnt;
}
int main()
{
int num,t;
cin>>t;
while(t--)
{
cin>>num;
cout<<numberOfStep(num)<<endl;
}
return 0;
}
|
|
|
|