C++ 如何在C+中的字符串2D数组中存储字符串数据+;
我想在2D数组t[0][0]的第一个索引处的第一个元素中存储数据! 我写这段代码:C++ 如何在C+中的字符串2D数组中存储字符串数据+;,c++,string,loops,multidimensional-array,C++,String,Loops,Multidimensional Array,我想在2D数组t[0][0]的第一个索引处的第一个元素中存储数据! 我写这段代码: int main() { string input; cout << "Enter string of code:\n"; cin >> input; queue < string > m; string t[100][3]; while (input != "^") { int i = 0;
int main()
{
string input;
cout << "Enter string of code:\n";
cin >> input;
queue < string > m;
string t[100][3];
while (input != "^")
{
int i = 0;
t[i][0] = input;
m.push(t[i][0]);
if (input == " ")
{
t[i + 1][0];
break;
}
cin >> input;
i++;
}
int c = 1;
while (!m.empty())
{
int i = 0;
t[i][0] = m.front();
string temp;
temp = t[i][0];
t[i][1] = check(temp);
//cout <<c<<" "<<t[i][0]<<" Is: " << t[i][1] << endl;
c++;
m.pop();
i++;
}
cout << endl;
cout << c << " " << t[0][0] << " Is: " << t[0][1] << endl;
system("Pause");
return 0;
}
intmain()
{
字符串输入;
cout>输入;
队列m;
字符串t[100][3];
while(输入!=“^”)
{
int i=0;
t[i][0]=输入;
m、 推(t[i][0]);
如果(输入==“”)
{
t[i+1][0];
打破
}
cin>>输入;
i++;
}
int c=1;
而(!m.empty())
{
int i=0;
t[i][0]=m.front();
字符串温度;
温度=t[i][0];
t[i][1]=检查(温度);
//cout在while循环上方声明并初始化i
,如下所示:
int i = 0;
while (!m.empty())
{
t[i][0] = m.front();
...
让我在这里解释一下(在代码中)发生了什么:
应发出此类警告:
main.cpp:22:23: warning: expression result unused [-Wunused-value]
t[i + 1][0];
~~~~~~~~ ~^
我通过如下方式编译您的代码得到:
int i = 0;
while (!m.empty())
{
t[i][0] = m.front();
...
g++-Wall main.cpp
在国旗墙可以显示所有警告的地方,很酷,让这成为你的朋友
正如现在发生的那样,这是很有帮助的,因为这一行不会对代码产生任何影响
PS:当然,我不知道您的代码中有什么check()
,所以我只能说这些。在while循环上方声明并初始化I
,如下所示:
int i = 0;
while (!m.empty())
{
t[i][0] = m.front();
...
让我在这里解释一下(在代码中)发生了什么:
应发出此类警告:
main.cpp:22:23: warning: expression result unused [-Wunused-value]
t[i + 1][0];
~~~~~~~~ ~^
我通过如下方式编译您的代码得到:
int i = 0;
while (!m.empty())
{
t[i][0] = m.front();
...
g++-Wall main.cpp
在国旗墙可以显示所有警告的地方,很酷,让这成为你的朋友
正如现在发生的那样,这是很有帮助的,因为这一行不会对代码产生任何影响
当然,我不知道什么是check()
你的代码中有,所以这就是我能说的。你应该在while循环上面声明int I
。@jhnslschnr感谢你的帮助你应该在while循环上面声明int I
。@jhnslschnr感谢你的帮助非常感谢,它解决了我在这段代码中遇到的所有问题,我无法相信时间有多长我花了很多时间来解决这个问题,非常感谢!非常感谢,它解决了我在代码中遇到的所有问题,我无法相信我花了多少时间来解决这个问题,非常感谢!