c++ - C++中的运行时错误字符串声明

您好我有这样的代码:

#include <iostream>
#include <cstdio>
using namespace std;  
int main () {
    std::string s="fawwaz"; 
  ...
}

然后我使用从gcc.gnu.org下载的gnu gcc在线安装程序,用G++对其进行了编译,该编译运行没有任何错误和警告,但是当我运行时,出现错误“程序a.exe已停止工作”。
并且程序运行无任何错误。然后,我尝试编译原始文件(在字符串声明的前面没有双反斜杠),程序已编译并成功运行。

有什么解决方案?哪里出问题了?他们有什么办法解决我的问题,以便我可以通过命令行而不是Microsoft Visual C++来编译程序,因为通过命令行编译会更快? :D

谢谢

这是完整的代码:
     #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/

相关文章:

c++ - 没有匹配的函数用于调用c++

c# - 编译内容项目时出错

java - 在PHP中获取Java编译错误

c++ - Count.h :10:5: error: ISO C++ forbids declar

java - 编写一个程序,询问产品代码,产品数量并汇总所有价格

java - 找不到符号(扩展另一个类)

sql - Oracle数据库触发器编译问题

c# - C#在数学表达式中使用未分配的变量

java - 错误: The local variable jars may not have be

c++ - 将文本文件读入结构并显示数组