こんにちは、これは私のコードです:私は、ユーザー、文字列からの入力を受け付けるプログラムを作成しようとしているC++整数配列に文字列を変換
#include<iostream>
#include <stdio.h>
#include <math.h>
void bubbleSort(int ar[]);
using namespace std;
int main()
{
char t = 'f';
char *t1;
char **t2;
cout<<t;
int choice;
std::cout << "\nWelcome to the algortihm tester!\n";
std::cout << "What algorithm would you like to test?";
std::cout << "\nChoose: \n1.Bubble Sort\n2.Selection Sort\n3.Insertion Sort\n";
scanf("\n%d", &choice);
switch(choice)
{
case 1:
std:: string trash;
std::string str;
std::cout << "\nINPUT:";
std::getline (std::cin,str);
std::getline(std::cin,trash);
int* myarray = new int[str.size() ];
std::copy(str.begin(), str.end(), myarray);
bubbleSort(myarray);
break;
}
}
void bubbleSort(int myarray[])
{
int length = sizeof(myarray)/sizeof(myarray[0]);
int i;
for(i=(length-1); i >= 0; i--)
{
for(int j =1; j<=i; j++)
{
if (myarray[j-1]>myarray[j])
{
int temp = myarray[j-1];
myarray[j-1]=myarray[j];
myarray[j]=temp;
}
}
}
}
、それを配列にコピーし、その取得しを配列は関数bubbleSort
に渡されます。しかし、私はそれを実行するとき、私は結果が0になる、つまり、文字列が配列に正しくコピーされなかったことを意味します。私はC++を初めて使い慣れていて、シンタックスにはそれほど精通していません。文字列を整数配列に変換するにはどうすればよいですか?
あなたのコードはそのままです。 'main'関数と' switch'ステートメントは不完全です。 – InternetAussie
私はそれらのコードを取ったので、私はちょうど1の場合にあるbubblesortを評価したかったので、 –