【发布时间】:2018-05-02 06:18:52
【问题描述】:
my code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
char str1[1000000];
char newString[1000][1000];
int i,j,ctr;
cout <<" \n\n Split string by space into words :"<< endl;
cout << "---------------------------------------\n";
cout << " Input a string : ";
cin >> str1 >> sizeof(str1) >> stdin;
j=0; ctr=0;
for(i=0;i<=(strlen(str1));i++)
{
// if space or NULL found, assign NULL into newString[ctr]
if(str1[i]==' '||str1[i]=='\0')
{
newString[ctr][j]='\0';
ctr++; //for next word
j=0; //for next word, init index to 0
}
else
{
newString[ctr][j]=str1[i];
j++;
}
}
cout << "\n Strings or words after split by space are :\n";
for(i=0;i < ctr;i++)
cout << newString[i];
return 0;
}
错误说明:
错误 1 错误 C2679: 二进制 '>>' : 找不到运算符 'unsigned int' 类型的右手操作数(或者没有可接受的 转换)c:\users\ayah atiyeh\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\source.cpp 14 3 IntelliSense:没有运算符“>>”匹配这些操作数 操作数类型为:std::basic_istream> >> unsigned int c:\Users\Ayah Atiyeh\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Source.cpp 14
【问题讨论】:
-
你为什么不直接使用
std::string?顺便说一句 - 你认为cin >> str1 >> sizeof(str1) >> stdin;是什么意思? -
请问我应该在哪里使用std::string?
-
>> sizeof(str1)什么? -
对字符串使用 std::string。对数组使用 std::vector。