我的程序中出现以下错误,请帮忙!我更新了!! [英] I have the belows error in my program please help! I update it!!
本文介绍了我的程序中出现以下错误,请帮忙!我更新了!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<pre lang="C++">#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
int accumulator =0;
int n;
int i=0;
int x=00;
string c;
const char *b;
int memory[100];
ifstream ifs;
int counter=0;
ifs.open("program.txt",ios::in);
if(ifs){
for(int i=0 ; i<100 && !ifs.eof();i++){
getline(ifs,c);
b=c.c-str();
memory[i]=atoi(b);
counter++;
}
ifs.close();
}else{
cout<<"Error";
}
for(int i=0 ;i<counter;i++){
cout<<x<<" ?"<<memory[i]<<endl;
}
cout<<"*** Welcome to Simpletron! ***\n";
cout<<"*** Please enter your program one instruction ***\n";
cout<<"*** (or data word) at a time. I will type the ***\n";
cout<<"*** location number and a question mark (?). ***\n";
cout<<"*** You then type the word for that location. ***\n";
cout<<"*** Type the sentinel -99999 to stop entering ***\n";
cout<<"*** your program. ***\n";
//2 raghame avale ram
int opCode ;
//2raghame dovome ram
int operand ;
int instructionRegister;
for(int i=0;i<counter;i++){
instructionRegister=memory[i];
opCode =instructionRegister/100;
operand =instructionRegister%100;
switch (opCode ){
case 10:
//Read a word from the keyboard into a specific location in memory.
cout<<"plz enter a number:\n";
cin>>memory[operand];
break;
case 11:
//Write a word from a specific location in memory to the screen.
cout<<memory[operand]<<''\n'';
break;
case 20:
//Load a word from a specific location in memory into the accumulator.
accumulator=memory[operand];
break;
case 21:
//Store a word from the accumulator into a specific location in memory.
memory[operand]=accumulator;
break;
case 30:
//Add a word from a specific location in memory to the word in the accumulator(Resgister) -leave result in accumulator.
accumulator+=memory[operand];
break;
case 31:
//Subtract a word from a specific location in memory from the word in the accumulator(Resgister) -leave result in accumulator.
accumulator-=memory[operand];
break;
case 32:
//Divide a word from a specific location in memory into the word in the accumulator(Resgister) -leave result in accumulator.
accumulator=memory[operand]/accumulator;
break;
case 33:
//Multiply a word from a specific location in memory by the word in the accumulator(Resgister) -leave result in accumulator.
accumulator=memory[operand]*accumulator;
break;
//case 40:
// i = memory[operand] - 1;
//break;
// case 41:
//Branch to a specific location in memory if the accumulator is negative.
// i = (accumulator < 0 ? (memory[operand] - 1) : i);
//break;
// case 42:
//Branch to a specific location in memory if the accumulator is zero.
//i = (accumulator == 0 ? (memory[operand] - 1) : i);
// break;
//case 43:
//Halt the program has completed its task.
// i = 101;
// break;
/*default:
Cout<<"Error: Wrong operation code. Program halt";
break;*/
}
}
getch();
return 0;
}
Error 1 error C2039: 'c' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>' c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp 32
Error 2 error C3861: 'str': identifier not found c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp 32
3 IntelliSense: class "std::basic_string<char, std::char_traits<char>, std::allocator<char>>" has no member "c" c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp 32
4 IntelliSense: identifier "str" is undefined c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp 32
:confused:
:confused:
推荐答案
也许,如果您查看源文件中的第32行
Perhaps, if you look at line number 32 in your source file
Error 1 error C2039: 'c' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>' c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp 32
最后的数字是行号.
在VS中,可以通过按CTRL + G转到特定的行号.
既然您似乎没有向我们显示错误行,这完全取决于您,但是我怀疑存在拼写错误!
The number at the end is the line number.
In VS, you can go to a specific line number by pressing CTRL+G.
Since you don''t appear to have shown us the line with the error, it is going to be up to you, but I suspect a spelling error!
OriginalGriff是绝对正确的:
OriginalGriff is absolutely correct:
if(ifs){
for(int i=0 ; i<100 && !ifs.eof();i++){
getline(ifs,c);
b=c.c_str(); //you had "c-str"
memory[i]=atoi(b);
counter++;
}
ifs.close();
}
您发布的代码与您的错误无关.我猜你在某个地方写了
The code you posted is not related to your errors. I would guess you somewhere have written
string s;
s.c;
// or
s.c();
您打算写s.c_str()
吗?
在第32行上检查文件c:\ users \ sama \ documents \ visual studio 2010 \ projects \ 11 \ 11 \ 11.cpp
Did you intend to write s.c_str()
?
Check the file c:\users\sama\documents\visual studio 2010\projects\11\11\11.cpp on line 32
这篇关于我的程序中出现以下错误,请帮忙!我更新了!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文