#include<sstream>
#include<iostream>
using namespace std;
int main(){
string line = "test one two three. \n another one \n";
string arr[8];
cout<<line;
int i = 0;
stringstream ssin(line);
while (ssin.good() && i < 8){
ssin >> arr[i];
++i;
}
for(i = 0; i < 8; i++){
cout << arr[i];
}
return 0;
}
//現在我想打印剛剛在字符串中的換行符(「\ n」)之前的那些元素。如何檢查字符串數組是否在C++中有換行符?
感謝它的工作! –