+ 1

How to do this in C++?

input: "abh" output: "a" "b" "h"

24th May 2017, 7:12 AM
School Dog
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 ****
24th May 2017, 7:19 AM
jay
jay - avatar
+ 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; }
24th May 2017, 7:57 AM
Enas Emad
Enas Emad - avatar
+ 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 :)
24th May 2017, 11:08 AM
Enas Emad
Enas Emad - avatar
+ 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
24th May 2017, 7:44 AM
Nguyễn Hồng Phúc
Nguyễn Hồng Phúc - avatar
+ 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 :|
24th May 2017, 8:30 AM
Enas Emad
Enas Emad - avatar
+ 4
@Nguyên . what is the purpose of system in your code ?
24th May 2017, 8:05 AM
Enas Emad
Enas Emad - avatar
+ 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.
24th May 2017, 8:08 AM
Enas Emad
Enas Emad - avatar
+ 4
did you mean (system)will run well on pc ?
24th May 2017, 8:16 AM
Enas Emad
Enas Emad - avatar
+ 3
.... pause. prevents the console window from closing
24th May 2017, 8:06 AM
jay
jay - avatar
+ 3
https://code.sololearn.com/cjoF20p5GA98/?ref=app i've coded a similar thing, to transpose an input vertically.
24th May 2017, 10:49 AM
MGlossCode
MGlossCode - avatar
+ 3
😃
24th May 2017, 4:35 PM
jay
jay - avatar
+ 2
@Nguyên: lol. i knew there was an easier way
24th May 2017, 7:54 AM
jay
jay - avatar
+ 2
in codeplayground or on your pc
24th May 2017, 8:13 AM
jay
jay - avatar
+ 2
The program is written in visual studio. It means stopping the screen to see results
24th May 2017, 8:22 AM
Nguyễn Hồng Phúc
Nguyễn Hồng Phúc - avatar
+ 2
@Enas Emad I think if the input is a thousand characters, your way is a bit hard :v :V
24th May 2017, 8:24 AM
Nguyễn Hồng Phúc
Nguyễn Hồng Phúc - avatar
+ 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 ^^!
24th May 2017, 1:37 PM
Nguyễn Hồng Phúc
Nguyễn Hồng Phúc - avatar
+ 1
The question is already answered.
24th May 2017, 7:25 PM
Luyanda
Luyanda - avatar