您好我有这样的代码:
#include <iostream>
#include <cstdio>
using namespace std;
int main () {
std::string s="fawwaz";
...
}
#include <cstdio>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
void Cetak_Puzzle_Start(){
}
int main(int argc, char const *argv[])
{
string s;
ifstream file("input.txt");
vector<vector<int> > Puzzle_Start;
vector<vector<int> > Puzzle_Finish;
int Puzzle_size=0;
/*
* RETRIEVE PUZZLE SIZE
**/
getline(file,s);
for (int i = 0; i < s.length(); ++i)
Puzzle_size= (Puzzle_size*10) + (int) (s[i]-'0');
/*
* Set Zero ukuran 3x3 vector Puzzle start dan Puzzle finish
**/
vector<int> vtemp(Puzzle_size,0);
for (int i = 0; i < Puzzle_size; ++i)
{
Puzzle_Start.push_back(vtemp);
Puzzle_Finish.push_back(vtemp);
}
/*
* RETRIEVE START STATE
**/
getline(file,s);
int m=0,n=0; // dummy var for looping only m:pointer baris, n:pointer kolom,
for (int i = 0; i < s.length(); ++i)
if (n<Puzzle_size){
if (s[i]=',')
n++;
else if (s[i] >= '0' && s[i] <='9')
Puzzle_Start[m][n]= (Puzzle_Start[m][n] * 10) +(int) (s[i]-'0');
else if (s[i] ='B')
Puzzle_Start[m][n]=-1;
}else{
n=0; // Ganti baris
m++;
}
fclose(stdin);
/*
* CETAK PUZZLE
**/
// for (int i = 0; i < Puzzle_Start.size(); ++i){
// for (int j = 0; j < Puzzle_Start[i].size(); ++j)
// printf("%d ",Puzzle_Start[i][j]);
// printf("\n");
// }
return 0;
}
最佳答案
这是错误,
if (s[i]=',')
if (s[i]==',')
else if (s[i]='B')
else if (s[i]=='B')
=
(分配)和==
(相等)是一个很常见的错误
https://stackoverflow.com/questions/19134035/