小编use*_*301的帖子

如何将unicode字符串从C++传递到delphi?

我发现了很多关于从 Delphi 到 C++ 的主题,但仍然感到困惑。

std::string s1(" look  here ");
Run Code Online (Sandbox Code Playgroud)

将它传递给delphi代码的正确方法是什么?

这些都不起作用,产生错误的字符

char * s = (char *)s1.c_str();
Call_Delphi_func(s);
.......
Memo1.Lines.Add(UTF8String(PChar(pointer(s))));
Run Code Online (Sandbox Code Playgroud)

c++ delphi

-1
推荐指数
1
解决办法
666
查看次数

为什么我的代码中的循环停止运行?

我试图获取一个数字的因子并将它们的值输入到一个数组中,小数字工作正常,但是当我尝试使用大数字时,代码崩溃了。

#include <iostream>
#include <math.h>
using namespace std;

main(){
    int num,c=1,a[c],b;
    
    cin>>num;
    
        for(int i=1; i <= num; i++) {
         if (num % i == 0)
            a[c++]=i;
            
        }
            cout<<a[6];
        
}
Run Code Online (Sandbox Code Playgroud)

c++

-1
推荐指数
1
解决办法
40
查看次数

而真正的循环功能

据我所知,while循环可以这样做:

while (true) {
    // run this code
    if (condition satisfies)
        break; // return;
}
Run Code Online (Sandbox Code Playgroud)

所以我接受了它并且我在下面输入了以下主要功能,我的问题是当我在满足条件(5或更多)后放置一个printf语句时,它会停止并且不显示任何内容,如果我什么也没放,它工作的break语句循环通过5个不同的客户!我错过了关于while循环的任何内容,或者这是它的工作方式吗?

int main ()
{
    displayMenu();
    while (true)
    {
        int gasType,gallonsAmount,carWashOption,customerAmount ;
        float gasPrices[SIZE]={2.99,3.099,3.199,3.299}, washPrices[SIZE]=
        {3.50,3.00,3.00,2.50}, perGallonRate,perWashRate,total;
        float totalSum,totalGallonSum;
        gasType = getGasType();
        gallonsAmount = getGallons();
        carWashOption = getCarWash();
        perGallonRate = getGallonRate(gasPrices, gasType);
        if (carWashOption == 'Y')
        {
            perWashRate = getWashRate( washPrices, gasType );
            total = calcAmount(gallonsAmount, perGallonRate, perWashRate,&totalSum, &totalGallonSum);
        }
        else 
        {
            perWashRate = 0;
            total = calcAmount(gallonsAmount, perGallonRate, perWashRate,&totalSum, &totalGallonSum);
        }
        customerAmount++;// once we …
Run Code Online (Sandbox Code Playgroud)

c c++ while-loop

-2
推荐指数
1
解决办法
568
查看次数

C++ While循环终止,即使条件不满足

我希望程序继续要求值进行计算,直到标志为真,然后程序必须停止,但它只执行一次.我不知道我是否以正确的方式使用char,或者是否有更好的方法来执行带有标志的这些类型的while循环.任何帮助都会很棒.[在此处输入图片说明] [1]

int main()
{
    displayMenu();
    bool flag = false;
    while(!flag)
    {
        int choice = 0; int val1 = 0; int val2 = 0; int ans = 0;
        cout << "Enter your choice (1-5): ";
        cin >> choice;
        cout << "\nEnter integer 1: ";
        cin >> val1;
        cout << "\nEnter integer 2: ";
        cin >> val2;
        if(choice < 0 || choice > 5)
        {
            cout << "\nEnter a choice between 1-5: ";
            cin >> choice;
        }
        if (choice == 1) …
Run Code Online (Sandbox Code Playgroud)

c++ while-loop

-2
推荐指数
1
解决办法
126
查看次数

std :: list push_back()和pop_front()给出const错误

我正在从事一个编码项目,遇到了一些麻烦。当我尝试制作时,出现以下错误:

src/mean.cc:26:12: error: passing ‘const csce240::Mean’ as ‘this’ argument discards qualifiers [-fpermissive]
   pop_back();
            ^
In file included from /usr/include/c++/7/list:63:0,
                 from inc/mean.h:9,
                 from src/mean.cc:2:
/usr/include/c++/7/bits/stl_list.h:1152:7: note:   in call to ‘void std::__cxx11::list<_Tp, _Alloc>::pop_back() [with _Tp = double; _Alloc = std::allocator<double>]’
       pop_back() _GLIBCXX_NOEXCEPT
       ^~~~~~~~
src/mean.cc:33:29: error: passing ‘const csce240::Mean’ as ‘this’ argument discards qualifiers [-fpermissive]
   push_front(tempList.back());
                             ^
In file included from /usr/include/c++/7/list:63:0,
                 from inc/mean.h:9,
                 from src/mean.cc:2:
/usr/include/c++/7/bits/stl_list.h:1067:7: note:   in call to ‘void std::__cxx11::list<_Tp, _Alloc>::push_front(const value_type&) [with _Tp = double; _Alloc = std::allocator<double>; std::__cxx11::list<_Tp, …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

-2
推荐指数
1
解决办法
60
查看次数

当我输入与数组中的数字匹配的费用数字时,为什么我的程序无法运行

为什么当我输入与数组中的数字匹配的费用数字时,我的程序无法运行。请参考函数

#include <iostream>
#include <cmath>
using namespace std;

string returnWord(int arr[], int SZ)
{
    int nums = 0;
    string answer;
    cout << "Please enter a charge number: ";
    cin >> nums;
    for (int i = 0; i < SZ; i++) {
        if (nums == arr[i]) {
            answer = "This is Valid";
        }
        else {
            answer = "This is Invalid"; // When I enter the valid number this is what prints out
        }
    }
    return (answer);
}

int main()
{
    const …
Run Code Online (Sandbox Code Playgroud)

c++ arrays compare

-2
推荐指数
1
解决办法
61
查看次数

const之前的const和c ++之后的const

在函数标题/ prototype之后const之前和const之间有什么区别?另外在下面的例子中做什么?

例如.

const E& top() const throw(StackEmpty);
Run Code Online (Sandbox Code Playgroud)

c++

-4
推荐指数
1
解决办法
84
查看次数

如何在c ++中为数组分配大小?

如果我们用4个元素初始化数组,例如:

int array[4];
Run Code Online (Sandbox Code Playgroud)

我们可以分配这样的值,因为它还带有4个值:

for(int i=5;i<9;i++){    
    cin>>array[i];
}
Run Code Online (Sandbox Code Playgroud)

c++

-7
推荐指数
1
解决办法
105
查看次数

标签 统计

c++ ×8

while-loop ×2

arrays ×1

c ×1

c++11 ×1

compare ×1

delphi ×1