#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {
ifstream in("A06input.txt"); // Open for reading
ofstream out("A06output.txt"); // Open for writing string s;
int strLen = 0;
return 0;
}
23 Replies - 532 Views - Last Post: 24 February 2012 - 09:41 PM
#1
Not getting output
Posted 23 February 2012 - 06:22 PM
I am working on i/o files, the code I have generated The input file and it says "this is a testt This is also a test, this is yet another test. in the ouput put file, Im trying to get the all the T's capitalized. This is what I have so far. I know I want to create a string, Im lost at where to begin. I am trying to learn more about how i/o works. Thanks
Replies To: Not getting output
#4
Re: Not getting output
Posted 23 February 2012 - 07:39 PM
Ok so I have read some articles and I need to creat a string where I need to read everyline and make the t's capital. Im stuck, this is the string I have created so far, thanks
string s = "t"; s[0] = toupper(s[0]); cout << s << endl;
#5
Re: Not getting output
Posted 23 February 2012 - 07:44 PM
You could also code this the old fashioned way with a simple for loop.
Here's an example of what I mean:
This just uses the ascii values to alter from upper to lower case.
Hope this helps.
EDIT: here is a full on example that I just ran to make sure it works
Here's an example of what I mean:
for(i = 0; i < strlen(i); i++){
if(string[i] == 't'){ string[i] -= 32; }
}
This just uses the ascii values to alter from upper to lower case.
Hope this helps.
EDIT: here is a full on example that I just ran to make sure it works
#include <stdio.h>
#include <string.h>
int main(){
char input[3];
input[0] = 't';
input[1] = 't';
input[2] = 'T';
int i = 0;
for(i = 0; i < strlen(input)-1; i++){
if(input[i] == 't'){ input[i] -= 32; }
}
printf("%c%c%c\n",input[0],input[1],input[2]);
}
This post has been edited by raspinudo: 23 February 2012 - 07:50 PM
#6
Re: Not getting output
Posted 23 February 2012 - 08:05 PM
Thank you, When I am working with output files I am not sure why I am not able to compile. thanks so much. I am looking at articles and tutorials, I m just not able to put it all together, I guess. Im trying to learn C++
#7
Re: Not getting output
Posted 23 February 2012 - 08:15 PM
java101, on 23 February 2012 - 08:05 PM, said:
Thank you, When I am working with output files I am not sure why I am not able to compile. thanks so much. I am looking at articles and tutorials, I m just not able to put it all together, I guess. Im trying to learn C++
No problem man. For learning the basics there are many great options to get you started, here are a few links that really helped me along the way.
Great Video Tutorial Series: http://thenewboston....list.php?cat=16
^ These really got me started in C++
Great reference material: http://www.cplusplus.com/
^This site is great for looking up different functions, data structures and all of their respective nuances.
Good written tutorials you may find useful: http://www.cprogramming.com/
^This site also has helpful practice problems
Also, be sure to check out all of the beginner tutorials here on dic, many of them have helped me tremendously.
Good luck and happy coding.
#8
Re: Not getting output
Posted 23 February 2012 - 08:25 PM
thank you. I figured that I need to use the getline() function within a while loop to process the lines of the file.
getline(in, s) not for sure how to incorporate this in my code. thanks Im working on it now
getline(in, s) not for sure how to incorporate this in my code. thanks Im working on it now
#9
Re: Not getting output
Posted 23 February 2012 - 08:34 PM
For getline, you can use a loop like this:
while (getline(file, input) {
/*this stores the current line in the string variable input
here you can do whatever you want with it, then the loop will
grab the next line
*/
}
#10
Re: Not getting output
Posted 23 February 2012 - 08:36 PM
#11
#12
Re: Not getting output
Posted 23 February 2012 - 08:39 PM
I am trying to make all the "t's" in the lines : This is a test, This is also a test, This is yet another test capitol. I cannot find a tutorial to show me how to write code to find all the "t's" and make them capitol. please point me in the right direction. Thanks
#13
Re: Not getting output
Posted 23 February 2012 - 08:59 PM
Probably, the first thing to do is read each line of the input file and print it to the screen or to the file.
When that is done you can think about checking each character in the line to discover the lowercase t's.
Then you can consider how to alter them.
A string is a series of characters and you can access any character in the string and alter them if you wish.
Here you need to move along the string using a loop as in the link I posted earlier.
When that is done you can think about checking each character in the line to discover the lowercase t's.
Then you can consider how to alter them.
A string is a series of characters and you can access any character in the string and alter them if you wish.
Here you need to move along the string using a loop as in the link I posted earlier.
string s = "t"; s[0] = toupper(s[0]); cout << s << endl;
This post has been edited by #define: 23 February 2012 - 09:07 PM
#14
Re: Not getting output
Posted 23 February 2012 - 09:14 PM
Thanks Everyone for the help/tutoral pointers. So this is the code I have come up with and I think I am back where I started from , no output 
So I tried to rewrite the code, as from the beggining, and now I have one failed error. Please assist;
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {
ifstream in("A06input.txt"); // Open for reading
ofstream out("A06output.txt"); // Open for writing string s;
string s;
int strLen = 0;
int i = 0;
for(i = 0; i < strlen("This is a test"); i++){
{
cout << s[i];
}
{
while(getline(in,s));
}
system("pause");
return 0;
}
So I tried to rewrite the code, as from the beggining, and now I have one failed error. Please assist;
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {
ifstream in("A06input.txt"); // Open for reading
ofstream out("A06output.txt"); // Open for writing string s;
string s;
int strLen = 0;
int i = 0;
for(i = 0; i < strlen("This is a test"); i++){
{
cout << s[i];
}
{
while(getline(in,s));
}
system("pause");
return 0;
}
#15
Re: Not getting output
Posted 23 February 2012 - 09:49 PM
Post the complete error message exactly as it appears in your development environment. These messages have important information embedded in them to make the locating and fixing the errors easier.
Jim
Jim
|
|

New Topic/Question
Reply



MultiQuote





|