+ 1
How to do this in C++?
input: "abh" output: "a" "b" "h"
18 Answers
+ 6
std::string theString = "abcd";
std::vector<char> vChar(theString.begin(), theString.end())
for(unsigned int i = 0; i < vChar.size(); i++) {
std::cout << vChar[i] << std::endl;
}
**** There is probably an easier way to do this ****
+ 6
#include <iostream>
using namespace std;
int main() {
char x[3];
cin>>x[0]>>x[1]>>x[2];
cout<<x[0]<<endl<<x[1]<<endl<<x[2];
return 0;
}
+ 6
//I made some modifications :
#include <iostream>
using namespace std;
int main() {
char x[1000];
for(int i=0; i<1000; i++)
cin>>x[i];
for(int i=0; i<x[i]; i++)
cout<<x[i]<<endl;
return 0;
}
//....@Nguyen . Now I can input 1000 characters :)
+ 5
#include<iostream>
#include<string>
using namespace std;
int main() {
string str;
getline(cin, str);
for (int i =0 ; i < str.length(); i++)
cout << str.at(i)<<"\n";
system("pause");
return 0;
}
//I'm not good at English
+ 5
@Nguyên . Yes , I know just this way to input characters , but now I understand your code .
maybe my way is hard , but easy to understand :|
+ 4
@Nguyên . what is the purpose of system in your code ?
+ 4
I ran his code . but the compiler said that :system was not declared in the scope.
but when I deleted it , the code ran well.
+ 4
did you mean (system)will run well on pc ?
+ 3
.... pause. prevents the console window from closing
+ 3
https://code.sololearn.com/cjoF20p5GA98/?ref=app i've coded a similar thing, to transpose an input vertically.
+ 3
😃
+ 2
@Nguyên: lol. i knew there was an easier way
+ 2
in codeplayground or on your pc
+ 2
The program is written in visual studio. It means stopping the screen to see results
+ 2
@Enas Emad I think if the input is a thousand characters, your way is a bit hard :v :V
+ 1
@Enas Emad a thousand characters, no excess, no missing, great :p :p
Do you use social networking?
It would be great to be your friend
^^!
+ 1
The question is already answered.