【发布时间】:2013-10-08 15:59:46
【问题描述】:
你好,我有这样的代码:
#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;
}
【问题讨论】:
-
您必须向我们展示程序的其余部分。该错误与您显示的行无关。此外,如果您正在使用它,您应该
#include <string>。 -
简短、独立、正确(可编译),请举例:sscce.org
-
在
main末尾添加return 0;能解决问题吗? -
@RedX 这是完整的代码,抱歉识别错误
-
您的错误不能出现在您发布的代码中,因为您发布的代码无法编译(
kota未声明)。猜测错误可能与您声明 kota 的方式有关,所以很遗憾您错过了这一点。如果您需要帮助发布真实代码,否则您将让人们修复您发布的代码而不是您真正拥有的代码。这应该是显而易见的。
标签: c++ gcc compiler-construction compilation compiler-errors